Skip to content

Commit

Permalink
Merge pull request #285 from CannoliCatfish/dev
Browse files Browse the repository at this point in the history
Fixed harvest level check and template table screen
  • Loading branch information
CannoliCatfish authored Jun 14, 2022
2 parents 33ad35b + 8ed94fd commit 7a093bf
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cannolicatfish.rankine.recipe.AlloyingRecipe;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.renderer.GameRenderer;
Expand All @@ -33,13 +34,17 @@ public class TemplateTableScreen extends AbstractContainerScreen<TemplateTableCo
private static final Component DEPRECATED_TOOLTIP = new TranslatableComponent("rankine.deprecated");
private int scrollOff;
private boolean isSelected;
private static final int TEXTURE_WIDTH = 512;
private static final int TEXTURE_HEIGHT = 256;

public TemplateTableScreen(TemplateTableContainer container, Inventory inv, Component name) {
super(container, inv, name);
this.imageWidth = 276;
this.inventoryLabelX = 107;
}



private void setSelectedAlloyRecipe() {
this.menu.setCurrentRecipeIndex(this.selectedAlloyRecipe);
this.menu.tryMoveItems(this.selectedAlloyRecipe);
Expand Down Expand Up @@ -89,7 +94,7 @@ protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y)
RenderSystem.setShaderTexture(0, this.GUI);
int i = (this.width - this.imageWidth) / 2;
int j = (this.height - this.imageHeight) / 2;
blit(matrixStack, i, j, this.getBlitOffset(), 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 512);
blit(matrixStack, i, j, this.getBlitOffset(), 0.0F, 0.0F, this.imageWidth, this.imageHeight, 512, 256);
List<AlloyingRecipe> alloyRecipes = this.menu.getAlloyRecipes();
if (!alloyRecipes.isEmpty()) {
int k = this.selectedAlloyRecipe;
Expand Down Expand Up @@ -119,7 +124,8 @@ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialT
int l = i + 5 + 5;
//RenderSystem.pushMatrix();
//RenderSystem.enableRescaleNormal();
this.minecraft.getTextureManager().bindForSetup(GUI);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, GUI);
//this.renderScroller(matrixStack, i, j, alloyingRecipes);
int i1 = 0;

Expand All @@ -143,10 +149,10 @@ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialT
ItemStack itemstack3 = alloy.getResultItem();

//this.renderItemOverlay(matrixStack, itemstack1, itemstack, l, j1);
/*if (!itemstack2.isEmpty()) {
this.itemRenderer.renderItemAndEffectIntoGuiWithoutEntity(itemstack2, i + 5 + 35, j1);
this.itemRenderer.renderItemOverlays(this.font, itemstack2, i + 5 + 35, j1);
}*/
if (!itemstack2.isEmpty()) {
this.itemRenderer.renderAndDecorateFakeItem(itemstack2, i + 5 + 35, j1);
this.itemRenderer.renderGuiItemDecorations(this.font, itemstack2, i + 5 + 35, j1);
}

this.checkIfValid(matrixStack, alloy, i, j1);
this.itemRenderer.renderAndDecorateFakeItem(itemstack3, i + 5 + 68, j1);
Expand All @@ -168,11 +174,14 @@ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialT
}*/

for(AlloyButton alloyButton : this.tradeOfferButtons) {
if (alloyButton.isActive()) {
alloyButton.renderToolTip(matrixStack, mouseX, mouseY);
if (alloyButton != null) {
if (alloyButton.isActive()) {
alloyButton.renderToolTip(matrixStack, mouseX, mouseY);
}
alloyButton.visible = alloyButton.index < this.menu.getAlloyRecipes().size();
}

alloyButton.visible = alloyButton.index < this.menu.getAlloyRecipes().size();

}

//RenderSystem.popMatrix();
Expand All @@ -189,7 +198,8 @@ private void renderItemOverlay(PoseStack p_238841_1_, ItemStack p_238841_2_, Ite
} else {
this.itemRenderer.renderGuiItemDecorations(this.font, p_238841_3_, p_238841_4_, p_238841_5_, p_238841_3_.getCount() == 1 ? "1" : null);
this.itemRenderer.renderGuiItemDecorations(this.font, p_238841_2_, p_238841_4_ + 14, p_238841_5_, p_238841_2_.getCount() == 1 ? "1" : null);
this.minecraft.getTextureManager().bindForSetup(GUI);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, GUI);
this.setBlitOffset(this.getBlitOffset() + 300);
blit(p_238841_1_, p_238841_4_ + 7, p_238841_5_ + 12, this.getBlitOffset(), 0.0F, 176.0F, 9, 2, 256, 512);
this.setBlitOffset(this.getBlitOffset() - 300);
Expand All @@ -201,9 +211,11 @@ private boolean checkSeven(int p_214135_1_) {
return p_214135_1_ > 7;
}


private void checkIfValid(PoseStack p_238842_1_, AlloyingRecipe p_238842_2_, int p_238842_3_, int p_238842_4_) {
RenderSystem.enableBlend();
this.minecraft.getTextureManager().bindForSetup(GUI);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, GUI);
/*if (p_238842_2_.cannotMake(this.inventory,this.menu.getWorld())) {
blit(p_238842_1_, p_238842_3_ + 5 + 35 + 20, p_238842_4_ + 3, this.getBlitOffset(), 25.0F, 171.0F, 10, 9, 256, 512);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ public static void onItemPickup(PlayerEvent.ItemPickupEvent event) {
}
}

@SubscribeEvent
public static void onAlloyToolHarvest(PlayerEvent.HarvestCheck event) {
ItemStack stack = event.getPlayer().getMainHandItem();
if (stack.getItem() instanceof IAlloyTool) {
List<Tiers> tiers = Arrays.asList(Tiers.WOOD,Tiers.STONE,Tiers.IRON,Tiers.DIAMOND,Tiers.NETHERITE);
event.setCanHarvest(TierSortingRegistry.isCorrectTierForDrops(tiers.get(((IAlloyTool) stack.getItem()).getAlloyHarvestLevel(stack)),event.getTargetBlock()));
}
}

@SubscribeEvent
public static void registerCommands(RegisterCommandsEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static int getTier(ItemStack stack) {

public static boolean hasPowerRequired(ItemStack stack, int powerRequired) {
if (stack.getItem() instanceof BatteryItem) {
return stack.getDamageValue() + powerRequired < stack.getMaxDamage();
return stack.getDamageValue() + powerRequired <= stack.getMaxDamage();
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
Expand All @@ -30,13 +30,9 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.TierSortingRegistry;

public class AlloyAxeItem extends AxeItem implements IAlloyTool {
private static final Set<Material> EFFECTIVE_ON_MATERIALS = Sets.newHashSet(Material.WOOD, Material.NETHER_WOOD, Material.PLANT, Material.REPLACEABLE_PLANT, Material.BAMBOO, Material.VEGETABLE);
Expand All @@ -50,6 +46,12 @@ public AlloyAxeItem(Tier tier, float attackDamageIn, float attackSpeedIn, String
this.defaultAlloyRecipe = defaultAlloyRecipeIn;
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
List<Tiers> tiers = Arrays.asList(Tiers.WOOD,Tiers.STONE,Tiers.IRON,Tiers.DIAMOND,Tiers.NETHERITE);
return state.is(BlockTags.MINEABLE_WITH_AXE) && TierSortingRegistry.isCorrectTierForDrops(tiers.get(getAlloyHarvestLevel(stack)),state);
}

@Override
public float getDestroySpeed(ItemStack p_41004_, BlockState p_41005_) {
return p_41005_.is(BlockTags.MINEABLE_WITH_AXE) ? getAlloyMiningSpeed(p_41004_) : 1.0F;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.cannolicatfish.rankine.items.alloys;

import com.cannolicatfish.rankine.init.RankineTags;
import com.cannolicatfish.rankine.items.tools.CrowbarItem;
import com.cannolicatfish.rankine.recipe.helper.AlloyCustomHelper;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundSource;
Expand All @@ -25,8 +23,10 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.TierSortingRegistry;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

public class AlloyCrowbarItem extends CrowbarItem implements IAlloyTool {
Expand All @@ -38,6 +38,12 @@ public AlloyCrowbarItem(Tier tier, float attackDamageIn, float attackSpeedIn, St
this.defaultAlloyRecipe = defaultAlloyRecipeIn;
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
List<Tiers> tiers = Arrays.asList(Tiers.WOOD,Tiers.STONE,Tiers.IRON,Tiers.DIAMOND,Tiers.NETHERITE);
return state.is(RankineTags.Blocks.CROWBAR_EFFECTIVE) && !state.is(RankineTags.Blocks.CROWBAR_RESISTANT) && TierSortingRegistry.isCorrectTierForDrops(tiers.get(getAlloyHarvestLevel(stack)),state);
}

@Override
public Component getName(ItemStack stack) {
if (!IAlloyItem.getNameOverride(stack).isEmpty()) {
Expand All @@ -60,7 +66,7 @@ public boolean mineBlock(ItemStack stack, Level worldIn, BlockState state, Block
});
}

if ((isCorrectToolForDrops(state) || (canHarvestWithRetrieval(stack,state) && worldIn.getBlockEntity(pos) == null && worldIn.getFluidState(pos).isEmpty())) && !worldIn.isClientSide && !stack.isEmpty() && worldIn.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && !worldIn.restoringBlockSnapshots)
if ((isCorrectToolForDrops(stack,state) || (canHarvestWithRetrieval(stack,state) && worldIn.getBlockEntity(pos) == null && worldIn.getFluidState(pos).isEmpty())) && !worldIn.isClientSide && !stack.isEmpty() && worldIn.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && !worldIn.restoringBlockSnapshots)
{
double d0 = (double)(worldIn.random.nextFloat() * 0.5F) + 0.25D;
double d1 = (double)(worldIn.random.nextFloat() * 0.5F) + 0.25D;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.cannolicatfish.rankine.items.alloys;

import com.cannolicatfish.rankine.init.RankineRecipeTypes;
import com.cannolicatfish.rankine.init.RankineTags;
import com.cannolicatfish.rankine.items.tools.HammerItem;
import com.cannolicatfish.rankine.recipe.CrushingRecipe;
import com.cannolicatfish.rankine.recipe.helper.AlloyCustomHelper;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -27,6 +28,7 @@
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

import net.minecraft.world.item.Item.Properties;
Expand All @@ -36,14 +38,12 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.AnvilBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.TierSortingRegistry;

public class AlloyHammerItem extends HammerItem implements IAlloyTool {
private final String defaultComposition;
Expand All @@ -54,6 +54,12 @@ public AlloyHammerItem(Tier tier, int attackDamageIn, float attackSpeedIn, Strin
this.defaultAlloyRecipe = defaultAlloyRecipeIn;
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
List<Tiers> tiers = Arrays.asList(Tiers.WOOD,Tiers.STONE,Tiers.IRON,Tiers.DIAMOND,Tiers.NETHERITE);
return TierSortingRegistry.isCorrectTierForDrops(tiers.get(getAlloyHarvestLevel(stack)),state);
}

@Override
public Component getName(ItemStack stack) {
if (!IAlloyItem.getNameOverride(stack).isEmpty()) {
Expand Down Expand Up @@ -99,7 +105,7 @@ public boolean mineBlock(ItemStack stack, Level worldIn, BlockState state, Block
{
creativeFlag = ((Player) entityLiving).isCreative();
}
if (!worldIn.isClientSide && worldIn.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && !worldIn.restoringBlockSnapshots && !worldIn.isEmptyBlock(pos)) {
if (!worldIn.isClientSide && worldIn.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && !worldIn.restoringBlockSnapshots && !worldIn.isEmptyBlock(pos) && this.isCorrectToolForDrops(stack,state)) {
for (CrushingRecipe recipe : worldIn.getRecipeManager().getAllRecipesFor(RankineRecipeTypes.CRUSHING)) {
for (ItemStack s : recipe.getIngredientAsStackList()) {
if (s.getItem() == worldIn.getBlockState(pos).getBlock().asItem()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.cannolicatfish.rankine.recipe.helper.AlloyCustomHelper;
import com.google.common.collect.*;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
Expand All @@ -24,12 +24,8 @@

import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.TierSortingRegistry;

public class AlloyHoeItem extends HoeItem implements IAlloyTool {
private static final Set<Block> EFFECTIVE_ON_BLOCKS = ImmutableSet.of(Blocks.NETHER_WART_BLOCK, Blocks.WARPED_WART_BLOCK, Blocks.HAY_BLOCK, Blocks.DRIED_KELP_BLOCK, Blocks.TARGET, Blocks.SHROOMLIGHT, Blocks.SPONGE, Blocks.WET_SPONGE, Blocks.JUNGLE_LEAVES, Blocks.OAK_LEAVES, Blocks.SPRUCE_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.ACACIA_LEAVES, Blocks.BIRCH_LEAVES);
Expand All @@ -42,6 +38,12 @@ public AlloyHoeItem(Tier tier, float attackDamageIn, float attackSpeedIn, String
this.defaultAlloyRecipe = defaultAlloyRecipeIn;
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
List<Tiers> tiers = Arrays.asList(Tiers.WOOD,Tiers.STONE,Tiers.IRON,Tiers.DIAMOND,Tiers.NETHERITE);
return state.is(BlockTags.MINEABLE_WITH_AXE) && TierSortingRegistry.isCorrectTierForDrops(tiers.get(getAlloyHarvestLevel(stack)),state);
}

@Override
public Component getName(ItemStack stack) {
if (!IAlloyItem.getNameOverride(stack).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.cannolicatfish.rankine.items.alloys;

import com.cannolicatfish.rankine.init.RankineTags;
import com.cannolicatfish.rankine.items.tools.KnifeItem;
import com.cannolicatfish.rankine.recipe.helper.AlloyCustomHelper;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.util.*;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
Expand All @@ -21,11 +19,13 @@
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.TierSortingRegistry;

public class AlloyKnifeItem extends KnifeItem implements IAlloyTool {

Expand Down
Loading

0 comments on commit 7a093bf

Please sign in to comment.