~80 errors remaining. Need to properly add offhand support for most items

This commit is contained in:
aidancbrady committed 2016-05-25 23:48:28 -04:00
1 parent a89b8f666c
commit 79af86daae
40 files changed
+586 -436

No files matched your search

@@ -14,19 +14,22 @@ import mekanism.common.util.ItemDataUtils;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
public class ItemAtomicDisassembler extends ItemEnergized
{
@@ -132,7 +135,7 @@ public class ItemAtomicDisassembler extends ItemEnergized
Block block2 = coord.getBlock(player.worldObj);
block2.onBlockDestroyedByPlayer(player.worldObj, coord.getPos(), state);
player.worldObj.playAuxSFXAtEntity(null, 2001, coord.getPos(), meta << 12);
player.worldObj.playEvent(null, 2001, coord.getPos(), Block.getStateId(state));
player.worldObj.setBlockToAir(coord.getPos());
block2.breakBlock(player.worldObj, coord.getPos(), state);
block2.dropBlockAsItem(player.worldObj, coord.getPos(), state, 0);
@@ -152,7 +155,7 @@ public class ItemAtomicDisassembler extends ItemEnergized
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
public ActionResult<ItemStack> onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer, EnumHand hand)
{
if(!world.isRemote && entityplayer.isSneaking())
{
@@ -160,19 +163,19 @@ public class ItemAtomicDisassembler extends ItemEnergized
entityplayer.addChatMessage(new TextComponentString(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.modeToggle") + " " + EnumColor.INDIGO + getModeName(itemstack) + EnumColor.AQUA + " (" + getEfficiency(itemstack) + ")"));
}
return itemstack;
return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(!player.isSneaking())
{
if(!useHoe(stack, player, world, pos, side))
if(useHoe(stack, player, world, pos, side) == EnumActionResult.FAIL)
{
if(world.getBlockState(pos).getBlock() != Blocks.FARMLAND)
{
return false;
return EnumActionResult.FAIL;
}
}
@@ -200,60 +203,62 @@ public class ItemAtomicDisassembler extends ItemEnergized
break;
}
return true;
return EnumActionResult.SUCCESS;
}
return false;
return EnumActionResult.PASS;
}
private boolean useHoe(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side)
@SuppressWarnings("incomplete-switch")
private EnumActionResult useHoe(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing facing)
{
if(!player.canPlayerEdit(pos, side, stack) || (!player.capabilities.isCreativeMode && getEnergy(stack) < HOE_USAGE))
{
return false;
}
else {
UseHoeEvent event = new UseHoeEvent(player, stack, world, pos);
if(!playerIn.canPlayerEdit(pos.offset(facing), facing, stack))
{
return EnumActionResult.FAIL;
}
else {
int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos);
if(hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
if(MinecraftForge.EVENT_BUS.post(event))
{
return false;
}
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
if(event.getResult() == Result.ALLOW)
{
setEnergy(stack, getEnergy(stack)-HOE_USAGE);
return true;
}
if(facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up()))
{
if(block == Blocks.GRASS || block == Blocks.GRASS_PATH)
{
setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
return EnumActionResult.SUCCESS;
}
Block block1 = world.getBlockState(pos).getBlock();
boolean air = block1.isAir(world.getBlockState(pos.up()), world, pos.up());
if(block == Blocks.DIRT)
{
switch((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
{
case DIRT:
setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState());
return EnumActionResult.SUCCESS;
case COARSE_DIRT:
setBlock(stack, playerIn, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
return EnumActionResult.SUCCESS;
}
}
}
if(side != EnumFacing.DOWN && air && (block1 == Blocks.GRASS || block1 == Blocks.DIRT))
{
Block farm = Blocks.FARMLAND;
world.playSoundEffect(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, farm.stepSound.getStepSound(), (farm.stepSound.getVolume() + 1.0F) / 2.0F, farm.stepSound.getFrequency() * 0.8F);
if(world.isRemote)
{
return true;
}
else {
world.setBlockState(pos, farm.getDefaultState());
if(!player.capabilities.isCreativeMode)
{
setEnergy(stack, getEnergy(stack)-HOE_USAGE);
}
return true;
}
}
else {
return false;
}
}
return EnumActionResult.PASS;
}
}
protected void setBlock(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state)
{
worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
if(!worldIn.isRemote)
{
worldIn.setBlockState(pos, state, 11);
stack.damageItem(1, player);
}
}
public int getEfficiency(ItemStack itemStack)
{