mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
Stuffs (#865)
* Resolve dupe glitch Items using custom item entities return false in EntityJoinWorldEvent, making World#spawnEntity return false, making the stackSize not drop properly. * Closes #862 Well, I didn't really check it, but if that returns false that's their fault. * Closes #862 A bit of copypaste from ItemHoe never hurt anyone right?
This commit is contained in:
parent
3042592da9
commit
6042517947
3 changed files with 67 additions and 8 deletions
|
@ -16,15 +16,21 @@ import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.init.SoundEvents;
|
import net.minecraft.init.SoundEvents;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumActionResult;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraftforge.common.IPlantable;
|
import net.minecraftforge.common.IPlantable;
|
||||||
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -46,7 +52,7 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){
|
if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){
|
||||||
world.setBlockState(farmland, Blocks.FARMLAND.getDefaultState(), 2);
|
useHoeAt(world, pos.down());
|
||||||
world.setBlockToAir(pos);
|
world.setBlockToAir(pos);
|
||||||
world.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
world.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||||
|
|
||||||
|
@ -164,4 +170,57 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ItemStack hoe = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
private static ItemStack getHoeStack(){
|
||||||
|
if(hoe.isEmpty()) hoe = new ItemStack(Items.DIAMOND_HOE);
|
||||||
|
return hoe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EnumActionResult useHoeAt(World world, BlockPos pos)
|
||||||
|
{
|
||||||
|
|
||||||
|
EntityPlayer player = FakePlayerFactory.getMinecraft((WorldServer) world);
|
||||||
|
|
||||||
|
ItemStack itemstack = getHoeStack();
|
||||||
|
|
||||||
|
if (!player.canPlayerEdit(pos.offset(EnumFacing.UP), EnumFacing.UP, itemstack))
|
||||||
|
{
|
||||||
|
return EnumActionResult.FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(itemstack, player, world, pos);
|
||||||
|
if (hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
|
||||||
|
|
||||||
|
IBlockState iblockstate = world.getBlockState(pos);
|
||||||
|
Block block = iblockstate.getBlock();
|
||||||
|
|
||||||
|
if (world.isAirBlock(pos.up()))
|
||||||
|
{
|
||||||
|
if (block == Blocks.GRASS || block == Blocks.GRASS_PATH)
|
||||||
|
{
|
||||||
|
world.setBlockState(pos, Blocks.FARMLAND.getDefaultState());
|
||||||
|
return EnumActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block == Blocks.DIRT)
|
||||||
|
{
|
||||||
|
switch (iblockstate.getValue(BlockDirt.VARIANT))
|
||||||
|
{
|
||||||
|
case DIRT:
|
||||||
|
world.setBlockState(pos, Blocks.FARMLAND.getDefaultState());
|
||||||
|
return EnumActionResult.SUCCESS;
|
||||||
|
case COARSE_DIRT:
|
||||||
|
world.setBlockState(pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
|
||||||
|
return EnumActionResult.SUCCESS;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EnumActionResult.PASS;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,15 @@ import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockNetherWart;
|
import net.minecraft.block.BlockNetherWart;
|
||||||
import net.minecraft.block.BlockSoulSand;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.IPlantable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,9 +34,7 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
||||||
int use = 500;
|
int use = 500;
|
||||||
if(farmer.getEnergy() >= use){
|
if(farmer.getEnergy() >= use){
|
||||||
if(seed.getItem() == Items.NETHER_WART){
|
if(seed.getItem() == Items.NETHER_WART){
|
||||||
BlockPos below = pos.down();
|
if(world.getBlockState(pos.down()).getBlock().canSustainPlant(world.getBlockState(pos.down()), world, pos.down(), EnumFacing.UP, (IPlantable) Items.NETHER_WART)){
|
||||||
IBlockState stateBelow = world.getBlockState(below);
|
|
||||||
if(stateBelow.getBlock() instanceof BlockSoulSand && Blocks.NETHER_BRICK.canPlaceBlockAt(world, pos)){
|
|
||||||
world.setBlockState(pos, Blocks.NETHER_WART.getDefaultState(), 2);
|
world.setBlockState(pos, Blocks.NETHER_WART.getDefaultState(), 2);
|
||||||
farmer.extractEnergy(use);
|
farmer.extractEnergy(use);
|
||||||
return FarmerResult.SUCCESS;
|
return FarmerResult.SUCCESS;
|
||||||
|
@ -52,7 +52,8 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
||||||
IBlockState state = world.getBlockState(pos);
|
IBlockState state = world.getBlockState(pos);
|
||||||
if(state.getBlock() instanceof BlockNetherWart){
|
if(state.getBlock() instanceof BlockNetherWart){
|
||||||
if(state.getValue(BlockNetherWart.AGE) >= 3){
|
if(state.getValue(BlockNetherWart.AGE) >= 3){
|
||||||
List<ItemStack> output = state.getBlock().getDrops(world, pos, state, 0);
|
NonNullList<ItemStack> output = NonNullList.create();
|
||||||
|
state.getBlock().getDrops(output, world, pos, state, 0);
|
||||||
if(output != null && !output.isEmpty()){
|
if(output != null && !output.isEmpty()){
|
||||||
boolean toInput = farmer.addToSeedInventory(output, false);
|
boolean toInput = farmer.addToSeedInventory(output, false);
|
||||||
if(toInput || farmer.addToOutputInventory(output, false)){
|
if(toInput || farmer.addToOutputInventory(output, false)){
|
||||||
|
|
|
@ -67,11 +67,10 @@ public class TileEntityDropper extends TileEntityInventoryBase{
|
||||||
ItemStack theoreticalRemove = this.removeFromInventory(false);
|
ItemStack theoreticalRemove = this.removeFromInventory(false);
|
||||||
if(StackUtil.isValid(theoreticalRemove)){
|
if(StackUtil.isValid(theoreticalRemove)){
|
||||||
IBlockState state = this.world.getBlockState(this.pos);
|
IBlockState state = this.world.getBlockState(this.pos);
|
||||||
if(WorldUtil.dropItemAtSide(WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)), this.world, this.pos, StackUtil.setStackSize(theoreticalRemove.copy(), 1))){
|
WorldUtil.dropItemAtSide(WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)), this.world, this.pos, StackUtil.setStackSize(theoreticalRemove.copy(), 1));
|
||||||
this.removeFromInventory(true);
|
this.removeFromInventory(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack removeFromInventory(boolean actuallyDo){
|
public ItemStack removeFromInventory(boolean actuallyDo){
|
||||||
for(int i = 0; i < this.slots.getSlots(); i++){
|
for(int i = 0; i < this.slots.getSlots(); i++){
|
||||||
|
|
Loading…
Reference in a new issue