Skip to content
This repository was archived by the owner on May 13, 2021. It is now read-only.

Commit

Permalink
Update to new getDrops method since Forge broke the old one (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
TehNut committed Nov 11, 2017
1 parent a9331c2 commit 9f8da7b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import tehnut.resourceful.crops.ResourcefulCrops;
import tehnut.resourceful.crops.block.prop.PropertySeedType;
import tehnut.resourceful.crops.block.tile.TileSeedContainer;
import tehnut.resourceful.crops.core.RegistrarResourcefulCrops;
Expand Down Expand Up @@ -57,23 +57,21 @@ public void updateTick(World world, BlockPos pos, IBlockState state, Random rand
}

@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getFoodStack(getSeed(), world, pos));
if (getAge(state) >= 7)
drops.add(getFoodStack(getCrop(), world, pos));
return drops;
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
drops.add(getResourcefulStack(getSeed(), world, pos));
if (getAge(state) >= 7)
drops.add(getResourcefulStack(getCrop(), world, pos));
}

@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, @Nullable ItemStack stack) {
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, ItemStack stack) {
super.harvestBlock(world, player, pos, state, tile, stack);
world.setBlockToAir(pos);
}

@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest);
return willHarvest || super.removedByPlayer(state, world, pos, player, false);
}

@Override
Expand All @@ -83,7 +81,7 @@ public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World wo

@Override
public ItemStack getItem(World world, BlockPos pos, IBlockState state) {
return getFoodStack(getSeed(), world, pos);
return getResourcefulStack(getSeed(), world, pos);
}

@Override
Expand Down Expand Up @@ -149,7 +147,7 @@ public BlockResourcefulCrop init() {
return this;
}

private ItemStack getFoodStack(Item toDrop, IBlockAccess world, BlockPos pos) {
private ItemStack getResourcefulStack(Item toDrop, IBlockAccess world, BlockPos pos) {
TileSeedContainer cropTile = Util.getTile(TileSeedContainer.class, world, pos);
if (cropTile != null)
return ItemResourceful.getResourcefulStack(toDrop, cropTile.getSeedKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.ItemHandlerHelper;
import tehnut.resourceful.crops.block.tile.TileSeedContainer;
import tehnut.resourceful.crops.core.RegistrarResourcefulCrops;
import tehnut.resourceful.crops.core.data.Seed;
Expand Down Expand Up @@ -39,10 +40,7 @@ public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler
if (seed.getOutputs().length == 0)
return accessor.getStack();

ItemStack ret = seed.getOutputs()[0].getItem();
ret.setCount(1);

return ret;
return ItemHandlerHelper.copyStackWithSize(seed.getOutputs()[0].getItem(), 1);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void init(File seedDir, IForgeRegistry<Seed> seedRegistry) {
}
}

seeds.sort((seed1, seed2) -> ((Integer) seed1.getTier()).compareTo(seed2.getTier()));
seeds.sort(Comparator.comparingInt(Seed::getTier));

for (Seed seed : seeds) {
String sanity = sanityCheck(seed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public boolean apply(@Nullable ItemStack input) {

Seed seed = ((ItemResourceful) input.getItem()).getSeed(input);
SeedStack seedStack = new SeedStack((ItemResourceful) input.getItem(), seed.getRegistryName(), input.getCount());
boolean ret = seeds.contains(seedStack);
return ret;
return seeds.contains(seedStack);
}

@Override
Expand Down

0 comments on commit 9f8da7b

Please sign in to comment.