Fixed electric tree tap. Closes #1535

This commit is contained in:
drcrazy 2018-06-08 15:46:28 +03:00
parent 76735d93bd
commit 93e324cc11

View file

@ -31,7 +31,6 @@ import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -42,9 +41,11 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import prospector.shootingstar.ShootingStar; import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound; import prospector.shootingstar.model.ModelCompound;
import reborncore.common.powerSystem.PoweredItem; import reborncore.common.util.WorldUtils;
import techreborn.client.TechRebornCreativeTabMisc; import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler; import techreborn.events.TRRecipeHandler;
import techreborn.init.ModSounds; import techreborn.init.ModSounds;
@ -94,7 +95,6 @@ public class BlockRubberLog extends Block {
return this.getDefaultState().withProperty(SAP_SIDE, facing).withProperty(HAS_SAP, hasSap); return this.getDefaultState().withProperty(SAP_SIDE, facing).withProperty(HAS_SAP, hasSap);
} }
@SuppressWarnings({ "incomplete-switch" })
@Override @Override
public int getMetaFromState(IBlockState state) { public int getMetaFromState(IBlockState state) {
int tempMeta = 0; int tempMeta = 0;
@ -111,6 +111,12 @@ public class BlockRubberLog extends Block {
break; break;
case EAST: case EAST:
tempMeta = 3; tempMeta = 3;
break;
case UP:
tempMeta = 0;
break;
case DOWN:
tempMeta = 0;
} }
if (state.getValue(HAS_SAP)) { if (state.getValue(HAS_SAP)) {
tempMeta += 4; tempMeta += 4;
@ -161,31 +167,27 @@ public class BlockRubberLog extends Block {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ); super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND); ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
if (!stack.isEmpty()) if (stack.isEmpty()) {
if ((stack.getItem() instanceof ItemElectricTreetap && PoweredItem.canUseEnergy(20, stack)) || stack.getItem() instanceof ItemTreeTap) return false;
if (state.getValue(HAS_SAP)) { }
if (state.getValue(SAP_SIDE) == side) { IEnergyStorage capEnergy = null;
if (stack.getItem() instanceof ItemElectricTreetap) {
capEnergy = stack.getCapability(CapabilityEnergy.ENERGY, null);
}
if ((capEnergy != null && capEnergy.getEnergyStored() > 20) || stack.getItem() instanceof ItemTreeTap) {
if (state.getValue(HAS_SAP) && state.getValue(SAP_SIDE) == side) {
worldIn.setBlockState(pos, worldIn.setBlockState(pos,
state.withProperty(HAS_SAP, false).withProperty(SAP_SIDE, EnumFacing.getHorizontal(0))); state.withProperty(HAS_SAP, false).withProperty(SAP_SIDE, EnumFacing.getHorizontal(0)));
worldIn.playSound(null, pos.getX(), pos.getY(), worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS,
pos.getZ(), ModSounds.SAP_EXTRACT, 0.6F, 1F);
SoundCategory.BLOCKS, 0.6F, 1F);
if (!worldIn.isRemote) { if (!worldIn.isRemote) {
if (stack.getItem() instanceof ItemElectricTreetap) { if (capEnergy != null) {
PoweredItem.useEnergy(20, stack); capEnergy.extractEnergy(20, false);
} else { } else {
playerIn.getHeldItem(EnumHand.MAIN_HAND).damageItem(1, playerIn); playerIn.getHeldItem(EnumHand.MAIN_HAND).damageItem(1, playerIn);
} }
if (!playerIn.inventory.addItemStackToInventory(ItemParts.getPartByName("rubberSap").copy())) { if (!playerIn.inventory.addItemStackToInventory(ItemParts.getPartByName("rubberSap").copy())) {
Random rand = new Random(); WorldUtils.dropItem(ItemParts.getPartByName("rubberSap").copy(), worldIn, pos.offset(side));
BlockPos itemPos = pos.offset(side);
EntityItem item = new EntityItem(worldIn, itemPos.getX(), itemPos.getY(), itemPos.getZ(),
ItemParts.getPartByName("rubberSap").copy());
float factor = 0.05F;
item.motionX = rand.nextGaussian() * factor;
item.motionY = rand.nextGaussian() * factor + 0.2F;
item.motionZ = rand.nextGaussian() * factor;
worldIn.spawnEntity(item);
} }
if (playerIn instanceof EntityPlayerMP) { if (playerIn instanceof EntityPlayerMP) {
TRRecipeHandler.unlockTRRecipes((EntityPlayerMP) playerIn); TRRecipeHandler.unlockTRRecipes((EntityPlayerMP) playerIn);