Fixing base classes

This commit is contained in:
Michael Hillcox 2020-10-31 20:42:32 +00:00
parent 4eee99c75b
commit 42affe942f
No known key found for this signature in database
GPG key ID: 971C5B254742488F
10 changed files with 366 additions and 446 deletions

View file

@ -6,7 +6,7 @@ import de.ellpeck.actuallyadditions.common.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.common.fluids.InitFluids; import de.ellpeck.actuallyadditions.common.fluids.InitFluids;
import de.ellpeck.actuallyadditions.common.util.FluidStateMapper; import de.ellpeck.actuallyadditions.common.util.FluidStateMapper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.model.ModelBakery;
import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -15,8 +15,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View file

@ -1,16 +1,10 @@
package de.ellpeck.actuallyadditions.common.items; package de.ellpeck.actuallyadditions.common.items;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.blocks.metalists.TheColoredLampColors; import de.ellpeck.actuallyadditions.common.blocks.metalists.TheColoredLampColors;
import de.ellpeck.actuallyadditions.common.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.common.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.common.inventory.ContainerDrill; import de.ellpeck.actuallyadditions.common.inventory.ContainerDrill;
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.common.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.common.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.common.tile.TileEntityInventoryBase; import de.ellpeck.actuallyadditions.common.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.common.util.ItemStackHandlerAA; import de.ellpeck.actuallyadditions.common.util.ItemStackHandlerAA;
@ -18,47 +12,38 @@ import de.ellpeck.actuallyadditions.common.util.ItemUtil;
import de.ellpeck.actuallyadditions.common.util.StackUtil; import de.ellpeck.actuallyadditions.common.util.StackUtil;
import de.ellpeck.actuallyadditions.common.util.WorldUtil; import de.ellpeck.actuallyadditions.common.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.enchantment.Enchantments;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.init.Blocks; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResult; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.*;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.common.ToolType;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.List;
public class ItemDrill extends ItemEnergy { public class ItemDrill extends ItemEnergy {
public static final int HARVEST_LEVEL = 4; public static final int HARVEST_LEVEL = 4;
private static final int ENERGY_USE = 100; private static final int ENERGY_USE = 100;
public ItemDrill(String name) { public ItemDrill(Properties properties, String name) {
super(250000, 1000, name); super(properties.maxDamage(0).addToolType(ToolType.SHOVEL, HARVEST_LEVEL).addToolType(ToolType.PICKAXE, HARVEST_LEVEL), 250000, 1000, name);
this.setMaxDamage(0);
this.setHasSubtypes(true);
this.setHarvestLevel("shovel", HARVEST_LEVEL);
this.setHarvestLevel("pickaxe", HARVEST_LEVEL);
} }
/** /**
@ -67,11 +52,9 @@ public class ItemDrill extends ItemEnergy {
* @param stack The Drill * @param stack The Drill
*/ */
public static void loadSlotsFromNBT(IItemHandlerModifiable slots, ItemStack stack) { public static void loadSlotsFromNBT(IItemHandlerModifiable slots, ItemStack stack) {
NBTTagCompound compound = stack.getTagCompound(); CompoundNBT compound = stack.getOrCreateTag();
if (compound != null) {
TileEntityInventoryBase.loadSlots(slots, compound); TileEntityInventoryBase.loadSlots(slots, compound);
} }
}
/** /**
* Writes all of the Slots to NBT * Writes all of the Slots to NBT
@ -80,52 +63,49 @@ public class ItemDrill extends ItemEnergy {
* @param stack The Drill * @param stack The Drill
*/ */
public static void writeSlotsToNBT(IItemHandler slots, ItemStack stack) { public static void writeSlotsToNBT(IItemHandler slots, ItemStack stack) {
NBTTagCompound compound = stack.getTagCompound(); CompoundNBT compound = stack.getOrCreateTag();
if (compound == null) {
compound = new NBTTagCompound();
}
TileEntityInventoryBase.saveSlots(slots, compound); TileEntityInventoryBase.saveSlots(slots, compound);
stack.setTagCompound(compound); stack.setTag(compound);
} }
@Override @Override
//Places Blocks if the Placing Upgrade is installed public ActionResultType onItemUse(ItemUseContext context) {
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = context.getPlayer().getHeldItem(context.getHand());
ItemStack stack = player.getHeldItem(hand);
ItemStack upgrade = this.getHasUpgradeAsStack(stack, ItemDrillUpgrade.UpgradeType.PLACER); ItemStack upgrade = this.getHasUpgradeAsStack(stack, ItemDrillUpgrade.UpgradeType.PLACER);
if (StackUtil.isValid(upgrade)) { if (StackUtil.isValid(upgrade)) {
int slot = ItemDrillUpgrade.getSlotToPlaceFrom(upgrade); int slot = ItemDrillUpgrade.getSlotToPlaceFrom(upgrade);
if (slot >= 0 && slot < InventoryPlayer.getHotbarSize()) { if (slot >= 0 && slot < PlayerInventory.getHotbarSize()) {
ItemStack equip = player.inventory.getStackInSlot(slot); ItemStack equip = context.getPlayer().inventory.getStackInSlot(slot);
if (StackUtil.isValid(equip) && equip != stack) { if (StackUtil.isValid(equip) && equip != stack) {
ItemStack toPlaceStack = equip.copy(); ItemStack toPlaceStack = equip.copy();
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack); WorldUtil.setHandItemWithoutAnnoyingSound(context.getPlayer(), context.getHand(), toPlaceStack);
//tryPlaceItemIntoWorld could throw an Exception //tryPlaceItemIntoWorld could throw an Exception
try { try {
//Places the Block into the World //Places the Block into the World
if (toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL) { if (toPlaceStack.onItemUse(context) != ActionResultType.FAIL) {
if (!player.capabilities.isCreativeMode) { if (!context.getPlayer().isCreative()) {
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack.copy()); WorldUtil.setHandItemWithoutAnnoyingSound(context.getPlayer(), context.getHand(), toPlaceStack.copy());
} }
} }
} }
//Notify the Player and log the Exception //Notify the Player and log the Exception
catch (Exception e) { catch (Exception e) {
ActuallyAdditions.LOGGER.error("Player " + player.getName() + " who should place a Block using a Drill at " + player.posX + ", " + player.posY + ", " + player.posZ + " in World " + world.provider.getDimension() + " threw an Exception! Don't let that happen again!"); ActuallyAdditions.LOGGER.error("Player " + context.getPlayer().getName() + " who should place a Block using a Drill at " + context.getPlayer().getPosX() + ", " + context.getPlayer().getPosY() + ", " + context.getPlayer().getPosY() + " in World " + context.getWorld().getDimension() + " threw an Exception! Don't let that happen again!");
} }
player.inventory.setInventorySlotContents(slot, player.getHeldItem(hand)); context.getPlayer().inventory.setInventorySlotContents(slot, context.getPlayer().getHeldItem(context.getHand()));
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, stack); WorldUtil.setHandItemWithoutAnnoyingSound(context.getPlayer(), context.getHand(), stack);
return EnumActionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
} }
} }
return EnumActionResult.FAIL; return ActionResultType.FAIL;
} }
/** /**
* Checks if a certain Upgrade is installed and returns it as an ItemStack * Checks if a certain Upgrade is installed and returns it as an ItemStack
* *
@ -134,7 +114,7 @@ public class ItemDrill extends ItemEnergy {
* @return The Upgrade, if it's installed * @return The Upgrade, if it's installed
*/ */
public ItemStack getHasUpgradeAsStack(ItemStack stack, ItemDrillUpgrade.UpgradeType upgrade) { public ItemStack getHasUpgradeAsStack(ItemStack stack, ItemDrillUpgrade.UpgradeType upgrade) {
NBTTagCompound compound = stack.getTagCompound(); CompoundNBT compound = stack.getOrCreateTag();
if (compound == null) { return StackUtil.getEmpty(); } if (compound == null) { return StackUtil.getEmpty(); }
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerDrill.SLOT_AMOUNT); ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerDrill.SLOT_AMOUNT);
@ -149,22 +129,18 @@ public class ItemDrill extends ItemEnergy {
} }
@Override @Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
if (!world.isRemote && player.isSneaking() && hand == EnumHand.MAIN_HAND) { // todo: reimplement
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.DRILL.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ); if (!world.isRemote && player.isSneaking() && hand == Hand.MAIN_HAND) {
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.DRILL.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
} }
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand)); return new ActionResult<>(ActionResultType.PASS, player.getHeldItem(hand));
} }
@Override @Override
public int getMetadata(int damage) { public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) {
return damage;
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entity1, EntityLivingBase entity2) {
int use = this.getEnergyUsePerBlock(stack); int use = this.getEnergyUsePerBlock(stack);
if (!(entity2 instanceof EntityPlayer) || !((EntityPlayer) entity2).capabilities.isCreativeMode) { if (!(attacker instanceof PlayerEntity) || !((PlayerEntity) attacker).isCreative()) {
if (this.getEnergyStored(stack) >= use) { if (this.getEnergyStored(stack) >= use) {
this.extractEnergyInternal(stack, use, false); this.extractEnergyInternal(stack, use, false);
} }
@ -173,29 +149,31 @@ public class ItemDrill extends ItemEnergy {
} }
@Override @Override
public EnumRarity getRarity(ItemStack stack) { public Multimap<String, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot, ItemStack stack) {
return EnumRarity.EPIC;
}
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
Multimap<String, AttributeModifier> map = super.getAttributeModifiers(slot, stack); Multimap<String, AttributeModifier> map = super.getAttributeModifiers(slot, stack);
if (slot == EntityEquipmentSlot.MAINHAND) { // todo: operation might be wrong here
map.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Drill Modifier", this.getEnergyStored(stack) >= ENERGY_USE ? 8.0F : 0.1F, 0)); if (slot == EquipmentSlotType.MAINHAND) {
map.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool Modifier", -2.5F, 0)); map.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Drill Modifier", this.getEnergyStored(stack) >= ENERGY_USE ? 8.0F : 0.1F, AttributeModifier.Operation.ADDITION));
map.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool Modifier", -2.5F, AttributeModifier.Operation.ADDITION));
} }
return map; return map;
} }
@Override @Override
public float getDestroySpeed(ItemStack stack, IBlockState state) { public float getDestroySpeed(ItemStack stack, BlockState state) {
return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) ? this.hasExtraWhitelist(state.getBlock()) || state.getBlock().getHarvestTool(state) == null || state.getBlock().getHarvestTool(state).isEmpty() || this.getToolClasses(stack).contains(state.getBlock().getHarvestTool(state)) ? this.getEfficiencyFromUpgrade(stack) : 1.0F : 0.1F; return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack)
? (this.hasExtraWhitelist(state.getBlock())
|| state.getBlock().getHarvestTool(state) == null
|| this.getToolTypes(stack).contains(state.getBlock().getHarvestTool(state)))
? this.getEfficiencyFromUpgrade(stack)
: 1.0F
: 0.1F;
} }
@Override @Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) { public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, PlayerEntity player) {
boolean toReturn = false; boolean toReturn = false;
int use = this.getEnergyUsePerBlock(stack); int use = this.getEnergyUsePerBlock(stack);
if (this.getEnergyStored(stack) >= use) { if (this.getEnergyStored(stack) >= use) {
@ -215,12 +193,12 @@ public class ItemDrill extends ItemEnergy {
//Breaks the Blocks //Breaks the Blocks
if (!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)) { if (!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)) {
if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)) { if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)) {
toReturn = this.breakBlocks(stack, 2, player.world, pos, ray.sideHit, player); toReturn = this.breakBlocks(stack, 2, player.world, pos, ((BlockRayTraceResult)ray).getFace(), player);
} else { } else {
toReturn = this.breakBlocks(stack, 1, player.world, pos, ray.sideHit, player); toReturn = this.breakBlocks(stack, 1, player.world, pos, ((BlockRayTraceResult)ray).getFace(), player);
} }
} else { } else {
toReturn = this.breakBlocks(stack, 0, player.world, pos, ray.sideHit, player); toReturn = this.breakBlocks(stack, 0, player.world, pos, ((BlockRayTraceResult)ray).getFace(), player);
} }
//Removes Enchantments added above //Removes Enchantments added above
@ -232,22 +210,9 @@ public class ItemDrill extends ItemEnergy {
} }
@Override @Override
public boolean canHarvestBlock(IBlockState state, ItemStack stack) { public boolean canHarvestBlock(ItemStack stack, BlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) && (this.hasExtraWhitelist(block) || state.getMaterial().isToolNotRequired() || block == Blocks.SNOW_LAYER || block == Blocks.SNOW || (block == Blocks.OBSIDIAN ? HARVEST_LEVEL >= 3 : block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE ? block != Blocks.EMERALD_ORE && block != Blocks.EMERALD_BLOCK ? block != Blocks.GOLD_BLOCK && block != Blocks.GOLD_ORE ? block != Blocks.IRON_BLOCK && block != Blocks.IRON_ORE ? block != Blocks.LAPIS_BLOCK && block != Blocks.LAPIS_ORE ? block != Blocks.REDSTONE_ORE && block != Blocks.LIT_REDSTONE_ORE ? state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON || state.getMaterial() == Material.ANVIL : HARVEST_LEVEL >= 2 : HARVEST_LEVEL >= 1 : HARVEST_LEVEL >= 1 : HARVEST_LEVEL >= 2 : HARVEST_LEVEL >= 2 : HARVEST_LEVEL >= 2)); return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) && (this.hasExtraWhitelist(block) || state.getMaterial().isToolNotRequired() || block == Blocks.SNOW_BLOCK || block == Blocks.SNOW || (block == Blocks.OBSIDIAN ? HARVEST_LEVEL >= 3 : block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE ? block != Blocks.EMERALD_ORE && block != Blocks.EMERALD_BLOCK ? block != Blocks.GOLD_BLOCK && block != Blocks.GOLD_ORE ? block != Blocks.IRON_BLOCK && block != Blocks.IRON_ORE ? block != Blocks.LAPIS_BLOCK && block != Blocks.LAPIS_ORE ? block != Blocks.REDSTONE_ORE ? state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON || state.getMaterial() == Material.ANVIL : HARVEST_LEVEL >= 2 : HARVEST_LEVEL >= 1 : HARVEST_LEVEL >= 1 : HARVEST_LEVEL >= 2 : HARVEST_LEVEL >= 2 : HARVEST_LEVEL >= 2));
}
@Override
public Set<String> getToolClasses(ItemStack stack) {
HashSet<String> hashSet = new HashSet<>();
hashSet.add("pickaxe");
hashSet.add("shovel");
return hashSet;
}
@Override
public int getHarvestLevel(ItemStack stack, String toolClass, EntityPlayer player, IBlockState blockState) {
return HARVEST_LEVEL;
} }
/** /**
@ -309,26 +274,27 @@ public class ItemDrill extends ItemEnergy {
protected void registerRendering() { protected void registerRendering() {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
String name = this.getRegistryName() + "_" + TheColoredLampColors.values()[i].regName; String name = this.getRegistryName() + "_" + TheColoredLampColors.values()[i].regName;
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), new ResourceLocation(name), "inventory"); ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1), new ResourceLocation(name), "inventory");
} }
} }
@Override // @Override
@SideOnly(Side.CLIENT) // @SideOnly(Side.CLIENT)
public void getSubItems(CreativeTabs tabs, NonNullList<ItemStack> list) { // public void getSubItems(CreativeTabs tabs, NonNullList<ItemStack> list) {
if (this.isInCreativeTab(tabs)) { // if (this.isInCreativeTab(tabs)) {
for (int i = 0; i < 16; i++) { // for (int i = 0; i < 16; i++) {
this.addDrillStack(list, i); // this.addDrillStack(list, i);
} // }
} // }
} // }
// todo: fix this
private void addDrillStack(List<ItemStack> list, int meta) { private void addDrillStack(List<ItemStack> list, int meta) {
ItemStack stackFull = new ItemStack(this, 1, meta); ItemStack stackFull = new ItemStack(this, 1);
this.setEnergy(stackFull, this.getMaxEnergyStored(stackFull)); this.setEnergy(stackFull, this.getMaxEnergyStored(stackFull));
list.add(stackFull); list.add(stackFull);
ItemStack stackEmpty = new ItemStack(this, 1, meta); ItemStack stackEmpty = new ItemStack(this, 1);
this.setEnergy(stackEmpty, 0); this.setEnergy(stackEmpty, 0);
list.add(stackEmpty); list.add(stackEmpty);
} }
@ -370,23 +336,23 @@ public class ItemDrill extends ItemEnergy {
* @param world The World * @param world The World
* @param player The Player who breaks the Blocks * @param player The Player who breaks the Blocks
*/ */
public boolean breakBlocks(ItemStack stack, int radius, World world, BlockPos aPos, EnumFacing side, EntityPlayer player) { public boolean breakBlocks(ItemStack stack, int radius, World world, BlockPos aPos, Direction side, PlayerEntity player) {
int xRange = radius; int xRange = radius;
int yRange = radius; int yRange = radius;
int zRange = 0; int zRange = 0;
//Corrects Blocks to hit depending on Side of original Block hit //Corrects Blocks to hit depending on Side of original Block hit
if (side.getAxis() == Axis.Y) { if (side.getAxis() == Direction.Axis.Y) {
zRange = radius; zRange = radius;
yRange = 0; yRange = 0;
} }
if (side.getAxis() == Axis.X) { if (side.getAxis() == Direction.Axis.X) {
xRange = 0; xRange = 0;
zRange = radius; zRange = radius;
} }
//Not defined later because main Block is getting broken below //Not defined later because main Block is getting broken below
IBlockState state = world.getBlockState(aPos); BlockState state = world.getBlockState(aPos);
float mainHardness = state.getBlockHardness(world, aPos); float mainHardness = state.getBlockHardness(world, aPos);
//Break Middle Block first //Break Middle Block first
@ -397,9 +363,9 @@ public class ItemDrill extends ItemEnergy {
return false; return false;
} }
if (radius == 2 && side.getAxis() != Axis.Y) { if (radius == 2 && side.getAxis() != Direction.Axis.Y) {
aPos = aPos.up(); aPos = aPos.up();
IBlockState theState = world.getBlockState(aPos); BlockState theState = world.getBlockState(aPos);
if (theState.getBlockHardness(world, aPos) <= mainHardness + 5.0F) { if (theState.getBlockHardness(world, aPos) <= mainHardness + 5.0F) {
this.tryHarvestBlock(world, aPos, true, stack, player, use); this.tryHarvestBlock(world, aPos, true, stack, player, use);
} }
@ -414,7 +380,7 @@ public class ItemDrill extends ItemEnergy {
if (this.getEnergyStored(stack) >= use) { if (this.getEnergyStored(stack) >= use) {
//Only break Blocks around that are (about) as hard or softer //Only break Blocks around that are (about) as hard or softer
BlockPos thePos = new BlockPos(xPos, yPos, zPos); BlockPos thePos = new BlockPos(xPos, yPos, zPos);
IBlockState theState = world.getBlockState(thePos); BlockState theState = world.getBlockState(thePos);
if (theState.getBlockHardness(world, thePos) <= mainHardness + 5.0F) { if (theState.getBlockHardness(world, thePos) <= mainHardness + 5.0F) {
this.tryHarvestBlock(world, thePos, true, stack, player, use); this.tryHarvestBlock(world, thePos, true, stack, player, use);
} }
@ -440,13 +406,13 @@ public class ItemDrill extends ItemEnergy {
* @param player The Player breaking the Blocks * @param player The Player breaking the Blocks
* @param use The Energy that should be extracted per Block * @param use The Energy that should be extracted per Block
*/ */
private boolean tryHarvestBlock(World world, BlockPos pos, boolean isExtra, ItemStack stack, EntityPlayer player, int use) { private boolean tryHarvestBlock(World world, BlockPos pos, boolean isExtra, ItemStack stack, PlayerEntity player, int use) {
IBlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
float hardness = state.getBlockHardness(world, pos); float hardness = state.getBlockHardness(world, pos);
boolean canHarvest = (ForgeHooks.canHarvestBlock(block, player, world, pos) || this.canHarvestBlock(state, stack)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F); boolean canHarvest = (ForgeHooks.canHarvestBlock(state, player, world, pos) || this.canHarvestBlock(stack, state)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F);
if (hardness >= 0.0F && (!isExtra || canHarvest && !block.hasTileEntity(world.getBlockState(pos)))) { if (hardness >= 0.0F && (!isExtra || canHarvest && !block.hasTileEntity(world.getBlockState(pos)))) {
if (!player.capabilities.isCreativeMode) { if (!player.isCreative()) {
this.extractEnergyInternal(stack, use, false); this.extractEnergyInternal(stack, use, false);
} }
//Break the Block //Break the Block

View file

@ -9,7 +9,8 @@ public class ItemBase extends Item {
private final String name; private final String name;
public ItemBase(String name) { public ItemBase(Properties properties, String name) {
super(properties);
this.name = name; this.name = name;
this.register(); this.register();

View file

@ -1,82 +1,77 @@
package de.ellpeck.actuallyadditions.common.items.base; package de.ellpeck.actuallyadditions.common.items.base;
import java.text.NumberFormat;
import java.util.List;
import javax.annotation.Nullable;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.tile.CustomEnergyStorage; import de.ellpeck.actuallyadditions.common.tile.CustomEnergyStorage;
import de.ellpeck.actuallyadditions.common.util.AssetUtil; import de.ellpeck.actuallyadditions.common.util.AssetUtil;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.text.NumberFormat;
import java.util.List;
public abstract class ItemEnergy extends ItemBase { public abstract class ItemEnergy extends ItemBase {
private final int maxPower; private final int maxPower;
private final int transfer; private final int transfer;
public ItemEnergy(int maxPower, int transfer, String name) { public ItemEnergy(Properties properties, int maxPower, int transfer, String name) {
super(name); super(properties.maxStackSize(1), name);
this.maxPower = maxPower; this.maxPower = maxPower;
this.transfer = transfer; this.transfer = transfer;
this.setHasSubtypes(true);
this.setMaxStackSize(1);
} }
@Override // @Override
public boolean getShareTag() { // public boolean getShareTag() {
return true; // return true;
} // }
@Override @Override
public void addInformation(ItemStack stack, World playerIn, List<String> tooltip, ITooltipFlag advanced) { public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(cap -> {
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) {
NumberFormat format = NumberFormat.getInstance(); NumberFormat format = NumberFormat.getInstance();
tooltip.add(String.format("%s/%s Crystal Flux", format.format(storage.getEnergyStored()), format.format(storage.getMaxEnergyStored()))); // todo: migrate to i18n
} tooltip.add(new StringTextComponent(String.format("%s/%s Crystal Flux", format.format(cap.getEnergyStored()), format.format(cap.getMaxEnergyStored()))));
} });
} }
@Override @Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack) { public boolean hasEffect(ItemStack stack) {
return false; return false;
} }
@Override // todo: check this out
public void getSubItems(CreativeTabs tabs, NonNullList<ItemStack> list) { // @Override
if (this.isInCreativeTab(tabs)) { // public void getSubItems(CreativeTabs tabs, NonNullList<ItemStack> list) {
ItemStack stackFull = new ItemStack(this); // if (this.isInCreativeTab(tabs)) {
if (stackFull.hasCapability(CapabilityEnergy.ENERGY, null)) { // ItemStack stackFull = new ItemStack(this);
IEnergyStorage storage = stackFull.getCapability(CapabilityEnergy.ENERGY, null); // if (stackFull.hasCapability(CapabilityEnergy.ENERGY, null)) {
if (storage != null) { // IEnergyStorage storage = stackFull.getCapability(CapabilityEnergy.ENERGY, null);
this.setEnergy(stackFull, storage.getMaxEnergyStored()); // if (storage != null) {
list.add(stackFull); // this.setEnergy(stackFull, storage.getMaxEnergyStored());
} // list.add(stackFull);
} // }
// }
ItemStack stackEmpty = new ItemStack(this); //
this.setEnergy(stackEmpty, 0); // ItemStack stackEmpty = new ItemStack(this);
list.add(stackEmpty); // this.setEnergy(stackEmpty, 0);
} // list.add(stackEmpty);
} // }
// }
@Override @Override
public boolean showDurabilityBar(ItemStack itemStack) { public boolean showDurabilityBar(ItemStack itemStack) {
@ -85,103 +80,71 @@ public abstract class ItemEnergy extends ItemBase {
@Override @Override
public double getDurabilityForDisplay(ItemStack stack) { public double getDurabilityForDisplay(ItemStack stack) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { return stack.getCapability(CapabilityEnergy.ENERGY)
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null); .map(cap -> {
if (storage != null) { double maxAmount = cap.getMaxEnergyStored();
double maxAmount = storage.getMaxEnergyStored(); double energyDif = maxAmount - cap.getEnergyStored();
double energyDif = maxAmount - storage.getEnergyStored();
return energyDif / maxAmount; return energyDif / maxAmount;
} })
} .orElse(super.getDurabilityForDisplay(stack));
return super.getDurabilityForDisplay(stack);
} }
@Override @Override
public int getRGBDurabilityForDisplay(ItemStack stack) { public int getRGBDurabilityForDisplay(ItemStack stack) {
EntityPlayer player = ActuallyAdditions.PROXY.getCurrentPlayer(); PlayerEntity player = ActuallyAdditions.PROXY.getCurrentPlayer();
if (player != null && player.world != null) { if (player != null && player.world != null) {
float[] color = AssetUtil.getWheelColor(player.world.getTotalWorldTime() % 256); float[] color = AssetUtil.getWheelColor(player.world.getGameTime() % 256); // todo: validate that getGameTime is correct (check diff for old)
return MathHelper.rgb(color[0] / 255F, color[1] / 255F, color[2] / 255F); return MathHelper.rgb(color[0] / 255F, color[1] / 255F, color[2] / 255F);
} }
return super.getRGBDurabilityForDisplay(stack); return super.getRGBDurabilityForDisplay(stack);
} }
public void setEnergy(ItemStack stack, int energy) { public void setEnergy(ItemStack stack, int energy) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(cap -> ((CustomEnergyStorage) cap).setEnergyStored(energy));
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage instanceof CustomEnergyStorage) {
((CustomEnergyStorage) storage).setEnergyStored(energy);
}
}
} }
public int receiveEnergyInternal(ItemStack stack, int maxReceive, boolean simulate) { public int receiveEnergyInternal(ItemStack stack, int maxReceive, boolean simulate) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(cap -> ((CustomEnergyStorage) cap).receiveEnergyInternal(maxReceive, simulate));
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage instanceof CustomEnergyStorage) {
((CustomEnergyStorage) storage).receiveEnergyInternal(maxReceive, simulate);
}
}
return 0; return 0;
} }
public int extractEnergyInternal(ItemStack stack, int maxExtract, boolean simulate) { public int extractEnergyInternal(ItemStack stack, int maxExtract, boolean simulate) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(cap -> cap.extractEnergy(maxExtract, simulate));
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage instanceof CustomEnergyStorage) {
((CustomEnergyStorage) storage).extractEnergyInternal(maxExtract, simulate);
}
}
return 0; return 0;
} }
public int receiveEnergy(ItemStack stack, int maxReceive, boolean simulate) { public int receiveEnergy(ItemStack stack, int maxReceive, boolean simulate) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { return stack.getCapability(CapabilityEnergy.ENERGY).map(cap -> cap.receiveEnergy(maxReceive, simulate)).orElse(0);
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) { return storage.receiveEnergy(maxReceive, simulate); }
}
return 0;
} }
public int extractEnergy(ItemStack stack, int maxExtract, boolean simulate) { public int extractEnergy(ItemStack stack, int maxExtract, boolean simulate) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { return stack.getCapability(CapabilityEnergy.ENERGY).map(cap -> cap.extractEnergy(maxExtract, simulate)).orElse(0);
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) { return storage.extractEnergy(maxExtract, simulate); }
}
return 0;
} }
public int getEnergyStored(ItemStack stack) { public int getEnergyStored(ItemStack stack) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { return stack.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0);
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) { return storage.getEnergyStored(); }
}
return 0;
} }
public int getMaxEnergyStored(ItemStack stack) { public int getMaxEnergyStored(ItemStack stack) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { return stack.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getMaxEnergyStored).orElse(0);
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) { return storage.getMaxEnergyStored(); }
}
return 0;
} }
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
return new EnergyCapabilityProvider(stack, this); return new EnergyCapabilityProvider(stack, this);
} }
private static class EnergyCapabilityProvider implements ICapabilityProvider { private static class EnergyCapabilityProvider implements ICapabilityProvider {
public final CustomEnergyStorage storage; public final CustomEnergyStorage storage;
private final LazyOptional<CustomEnergyStorage> lazyStorage;
public EnergyCapabilityProvider(final ItemStack stack, ItemEnergy item) { public EnergyCapabilityProvider(final ItemStack stack, ItemEnergy item) {
this.storage = new CustomEnergyStorage(item.maxPower, item.transfer, item.transfer) { this.storage = new CustomEnergyStorage(item.maxPower, item.transfer, item.transfer) {
@Override @Override
public int getEnergyStored() { public int getEnergyStored() {
if (stack.hasTagCompound()) { if (stack.hasTag()) {
return stack.getTagCompound().getInteger("Energy"); return stack.getOrCreateTag().getInt("Energy");
} else { } else {
return 0; return 0;
} }
@ -189,25 +152,21 @@ public abstract class ItemEnergy extends ItemBase {
@Override @Override
public void setEnergyStored(int energy) { public void setEnergyStored(int energy) {
if (!stack.hasTagCompound()) { stack.getOrCreateTag().putInt("Energy", energy);
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setInteger("Energy", energy);
} }
}; };
lazyStorage = LazyOptional.of(() -> this.storage);
} }
@Nonnull
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) { public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
return this.getCapability(capability, facing) != null; if (cap == CapabilityEnergy.ENERGY) {
return this.lazyStorage.cast();
} }
@Nullable return LazyOptional.empty();
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(this.storage); }
return null;
} }
} }
} }

View file

@ -2,6 +2,7 @@ package de.ellpeck.actuallyadditions.common.proxy;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -24,7 +25,7 @@ public interface IProxy {
void addColoredBlock(Block block); void addColoredBlock(Block block);
EntityPlayer getCurrentPlayer(); PlayerEntity getCurrentPlayer();
default void sendBreakPacket(BlockPos pos) { default void sendBreakPacket(BlockPos pos) {
}; };

View file

@ -1,7 +1,7 @@
package de.ellpeck.actuallyadditions.common.tile; package de.ellpeck.actuallyadditions.common.tile;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
public interface ISharingEnergyProvider { public interface ISharingEnergyProvider {
@ -9,7 +9,7 @@ public interface ISharingEnergyProvider {
boolean doesShareEnergy(); boolean doesShareEnergy();
EnumFacing[] getEnergyShareSides(); Direction[] getEnergyShareSides();
boolean canShareTo(TileEntity tile); boolean canShareTo(TileEntity tile);
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.actuallyadditions.common.tile; package de.ellpeck.actuallyadditions.common.tile;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
public interface ISharingFluidHandler { public interface ISharingFluidHandler {
@ -8,6 +8,6 @@ public interface ISharingFluidHandler {
boolean doesShareFluid(); boolean doesShareFluid();
EnumFacing[] getFluidShareSides(); Direction[] getFluidShareSides();
} }

View file

@ -4,30 +4,28 @@ import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.common.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.common.util.VanillaPacketDispatcher; import de.ellpeck.actuallyadditions.common.util.VanillaPacketDispatcher;
import de.ellpeck.actuallyadditions.common.util.WorldUtil; import de.ellpeck.actuallyadditions.common.util.WorldUtil;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ITickable; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public abstract class TileEntityBase extends TileEntity implements ITickable { import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class TileEntityBase<T extends TileEntity> extends TileEntity implements ITickableTileEntity {
public final String name; public final String name;
public boolean isRedstonePowered; public boolean isRedstonePowered;
@ -37,125 +35,129 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
protected TileEntity[] tilesAround = new TileEntity[6]; protected TileEntity[] tilesAround = new TileEntity[6];
protected boolean hasSavedDataOnChangeOrWorldStart; protected boolean hasSavedDataOnChangeOrWorldStart;
public TileEntityBase(String name) { public TileEntityBase(TileEntityType<T> type, String name) {
super(type);
this.name = name; this.name = name;
} }
public static void init() { // public static void init() {
ActuallyAdditions.LOGGER.info("Registering TileEntities..."); // ActuallyAdditions.LOGGER.info("Registering TileEntities...");
//
// register(TileEntityCompost.class);
// register(TileEntityFeeder.class);
// register(TileEntityGiantChest.class);
// register(TileEntityGiantChestMedium.class);
// register(TileEntityGiantChestLarge.class);
// register(TileEntityGrinder.class);
// register(TileEntityFurnaceDouble.class);
// register(TileEntityInputter.class);
// register(TileEntityFishingNet.class);
// register(TileEntityFurnaceSolar.class);
// register(TileEntityHeatCollector.class);
// register(TileEntityItemRepairer.class);
// register(TileEntityBreaker.class);
// register(TileEntityDropper.class);
// register(TileEntityInputterAdvanced.class);
// register(TileEntityPlacer.class);
// register(TileEntityGrinderDouble.class);
// register(TileEntityCanolaPress.class);
// register(TileEntityFermentingBarrel.class);
// register(TileEntityOilGenerator.class);
// register(TileEntityCoalGenerator.class);
// register(TileEntityPhantomItemface.class);
// register(TileEntityPhantomLiquiface.class);
// register(TileEntityPhantomEnergyface.class);
// register(TileEntityPlayerInterface.class);
// register(TileEntityPhantomPlacer.class);
// register(TileEntityPhantomBreaker.class);
// register(TileEntityFluidCollector.class);
// register(TileEntityFluidPlacer.class);
// register(TileEntityLavaFactoryController.class);
// register(TileEntityCoffeeMachine.class);
// register(TileEntityPhantomBooster.class);
// register(TileEntityEnergizer.class);
// register(TileEntityEnervator.class);
// register(TileEntityXPSolidifier.class);
// register(TileEntitySmileyCloud.class);
// register(TileEntityLeafGenerator.class);
// register(TileEntityDirectionalBreaker.class);
// register(TileEntityRangedCollector.class);
// register(TileEntityAtomicReconstructor.class);
// register(TileEntityMiner.class);
// register(TileEntityFireworkBox.class);
// register(TileEntityPhantomRedstoneface.class);
// register(TileEntityLaserRelayItem.class);
// register(TileEntityLaserRelayEnergy.class);
// register(TileEntityLaserRelayEnergyAdvanced.class);
// register(TileEntityLaserRelayEnergyExtreme.class);
// register(TileEntityLaserRelayItemWhitelist.class);
// register(TileEntityItemViewer.class);
// register(TileEntityDisplayStand.class);
// register(TileEntityShockSuppressor.class);
// register(TileEntityEmpowerer.class);
// register(TileEntityLaserRelayFluids.class);
// register(TileEntityBioReactor.class);
// register(TileEntityFarmer.class);
// register(TileEntityItemViewerHopping.class);
// register(TileEntityBatteryBox.class);
// }
register(TileEntityCompost.class); // private static void register(Class<? extends TileEntityBase> tileClass) {
register(TileEntityFeeder.class); // try {
register(TileEntityGiantChest.class); // //This is hacky and dirty but it works so whatever
register(TileEntityGiantChestMedium.class); // ResourceLocation name = new ResourceLocation(ActuallyAdditions.MODID, tileClass.newInstance().name);
register(TileEntityGiantChestLarge.class); // GameRegistry.registerTileEntity(tileClass, name);
register(TileEntityGrinder.class); // } catch (Exception e) {
register(TileEntityFurnaceDouble.class); // ActuallyAdditions.LOGGER.fatal("Registering a TileEntity failed!", e);
register(TileEntityInputter.class); // }
register(TileEntityFishingNet.class); // }
register(TileEntityFurnaceSolar.class);
register(TileEntityHeatCollector.class);
register(TileEntityItemRepairer.class);
register(TileEntityBreaker.class);
register(TileEntityDropper.class);
register(TileEntityInputterAdvanced.class);
register(TileEntityPlacer.class);
register(TileEntityGrinderDouble.class);
register(TileEntityCanolaPress.class);
register(TileEntityFermentingBarrel.class);
register(TileEntityOilGenerator.class);
register(TileEntityCoalGenerator.class);
register(TileEntityPhantomItemface.class);
register(TileEntityPhantomLiquiface.class);
register(TileEntityPhantomEnergyface.class);
register(TileEntityPlayerInterface.class);
register(TileEntityPhantomPlacer.class);
register(TileEntityPhantomBreaker.class);
register(TileEntityFluidCollector.class);
register(TileEntityFluidPlacer.class);
register(TileEntityLavaFactoryController.class);
register(TileEntityCoffeeMachine.class);
register(TileEntityPhantomBooster.class);
register(TileEntityEnergizer.class);
register(TileEntityEnervator.class);
register(TileEntityXPSolidifier.class);
register(TileEntitySmileyCloud.class);
register(TileEntityLeafGenerator.class);
register(TileEntityDirectionalBreaker.class);
register(TileEntityRangedCollector.class);
register(TileEntityAtomicReconstructor.class);
register(TileEntityMiner.class);
register(TileEntityFireworkBox.class);
register(TileEntityPhantomRedstoneface.class);
register(TileEntityLaserRelayItem.class);
register(TileEntityLaserRelayEnergy.class);
register(TileEntityLaserRelayEnergyAdvanced.class);
register(TileEntityLaserRelayEnergyExtreme.class);
register(TileEntityLaserRelayItemWhitelist.class);
register(TileEntityItemViewer.class);
register(TileEntityDisplayStand.class);
register(TileEntityShockSuppressor.class);
register(TileEntityEmpowerer.class);
register(TileEntityLaserRelayFluids.class);
register(TileEntityBioReactor.class);
register(TileEntityFarmer.class);
register(TileEntityItemViewerHopping.class);
register(TileEntityBatteryBox.class);
}
private static void register(Class<? extends TileEntityBase> tileClass) {
try {
//This is hacky and dirty but it works so whatever
ResourceLocation name = new ResourceLocation(ActuallyAdditions.MODID, tileClass.newInstance().name);
GameRegistry.registerTileEntity(tileClass, name);
} catch (Exception e) {
ActuallyAdditions.LOGGER.fatal("Registering a TileEntity failed!", e);
}
}
@Override @Override
public final NBTTagCompound writeToNBT(NBTTagCompound compound) { public CompoundNBT write(CompoundNBT compound) {
this.writeSyncableNBT(compound, NBTType.SAVE_TILE); this.writeSyncableNBT(compound, NBTType.SAVE_TILE);
return compound; return compound;
} }
@Override @Override
public final void readFromNBT(NBTTagCompound compound) { public void read(CompoundNBT compound) {
this.readSyncableNBT(compound, NBTType.SAVE_TILE); this.readSyncableNBT(compound, NBTType.SAVE_TILE);
} }
@Nullable
@Override @Override
public final SPacketUpdateTileEntity getUpdatePacket() { public SUpdateTileEntityPacket getUpdatePacket() {
NBTTagCompound compound = new NBTTagCompound(); CompoundNBT compound = new CompoundNBT();
this.writeSyncableNBT(compound, NBTType.SYNC); this.writeSyncableNBT(compound, NBTType.SYNC);
return new SPacketUpdateTileEntity(this.pos, -1, compound); return new SUpdateTileEntityPacket(this.pos, -1, compound);
} }
@Override @Override
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { public final void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
this.readSyncableNBT(pkt.getNbtCompound(), NBTType.SYNC); this.readSyncableNBT(pkt.getNbtCompound(), NBTType.SYNC);
} }
@Override @Override
public final NBTTagCompound getUpdateTag() { public final CompoundNBT getUpdateTag() {
NBTTagCompound compound = new NBTTagCompound(); CompoundNBT compound = new CompoundNBT();
this.writeSyncableNBT(compound, NBTType.SYNC); this.writeSyncableNBT(compound, NBTType.SYNC);
return compound; return compound;
} }
@Override @Override
public final void handleUpdateTag(NBTTagCompound compound) { public final void handleUpdateTag(CompoundNBT compound) {
this.readSyncableNBT(compound, NBTType.SYNC); this.readSyncableNBT(compound, NBTType.SYNC);
} }
public final void sendUpdate() { public final void sendUpdate() {
if (this.world != null && !this.world.isRemote) VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this); if (this.world != null && !this.world.isRemote) VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
/* /*
todo: this wan't me
if(this.world != null && !this.world.isRemote){ if(this.world != null && !this.world.isRemote){
NBTTagCompound compound = new NBTTagCompound(); CompoundNBT compound = new CompoundNBT();
this.writeSyncableNBT(compound, NBTType.SYNC); this.writeSyncableNBT(compound, NBTType.SYNC);
NBTTagCompound data = new NBTTagCompound(); CompoundNBT data = new CompoundNBT();
data.setTag("Data", compound); data.setTag("Data", compound);
data.setInteger("X", this.pos.getX()); data.setInteger("X", this.pos.getX());
data.setInteger("Y", this.pos.getY()); data.setInteger("Y", this.pos.getY());
@ -165,25 +167,25 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
} }
public void writeSyncableNBT(CompoundNBT compound, NBTType type) { public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
if (type != NBTType.SAVE_BLOCK) super.writeToNBT(compound); if (type != NBTType.SAVE_BLOCK) super.write(compound);
if (type == NBTType.SAVE_TILE) { if (type == NBTType.SAVE_TILE) {
compound.setBoolean("Redstone", this.isRedstonePowered); compound.putBoolean("Redstone", this.isRedstonePowered);
compound.setInteger("TicksElapsed", this.ticksElapsed); compound.putInt("TicksElapsed", this.ticksElapsed);
compound.setBoolean("StopDrop", this.stopFromDropping); compound.putBoolean("StopDrop", this.stopFromDropping);
} else if (type == NBTType.SYNC && this.stopFromDropping) compound.setBoolean("StopDrop", this.stopFromDropping); } else if (type == NBTType.SYNC && this.stopFromDropping) compound.putBoolean("StopDrop", this.stopFromDropping);
if (this.isRedstoneToggle() && (type != NBTType.SAVE_BLOCK || this.isPulseMode)) { if (this.isRedstoneToggle() && (type != NBTType.SAVE_BLOCK || this.isPulseMode)) {
compound.setBoolean("IsPulseMode", this.isPulseMode); compound.putBoolean("IsPulseMode", this.isPulseMode);
} }
} }
public void readSyncableNBT(CompoundNBT compound, NBTType type) { public void readSyncableNBT(CompoundNBT compound, NBTType type) {
if (type != NBTType.SAVE_BLOCK) super.readFromNBT(compound); if (type != NBTType.SAVE_BLOCK) super.read(compound);
if (type == NBTType.SAVE_TILE) { if (type == NBTType.SAVE_TILE) {
this.isRedstonePowered = compound.getBoolean("Redstone"); this.isRedstonePowered = compound.getBoolean("Redstone");
this.ticksElapsed = compound.getInteger("TicksElapsed"); this.ticksElapsed = compound.getInt("TicksElapsed");
this.stopFromDropping = compound.getBoolean("StopDrop"); this.stopFromDropping = compound.getBoolean("StopDrop");
} else if (type == NBTType.SYNC) this.stopFromDropping = compound.getBoolean("StopDrop"); } else if (type == NBTType.SYNC) this.stopFromDropping = compound.getBoolean("StopDrop");
@ -192,22 +194,18 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
} }
} }
@Override // todo: re-eval
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) { // @Override
return !oldState.getBlock().isAssociatedBlock(newState.getBlock()); // public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
} // return !oldState.getBlock().isAssociatedBlock(newState.getBlock());
// }
public String getNameForTranslation() { public String getNameForTranslation() {
return "container." + ActuallyAdditions.MODID + "." + this.name + ".name"; return "container." + ActuallyAdditions.MODID + "." + this.name + ".name";
} }
@Override @Override
public ITextComponent getDisplayName() { public void tick() {
return new TextComponentTranslation(this.getNameForTranslation());
}
@Override
public final void update() {
this.updateEntity(); this.updateEntity();
} }
@ -227,14 +225,14 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
if (provider.doesShareEnergy()) { if (provider.doesShareEnergy()) {
int total = provider.getEnergyToSplitShare(); int total = provider.getEnergyToSplitShare();
if (total > 0) { if (total > 0) {
EnumFacing[] sides = provider.getEnergyShareSides(); Direction[] sides = provider.getEnergyShareSides();
int amount = total / sides.length; int amount = total / sides.length;
if (amount <= 0) { if (amount <= 0) {
amount = total; amount = total;
} }
for (EnumFacing side : sides) { for (Direction side : sides) {
TileEntity tile = this.tilesAround[side.ordinal()]; TileEntity tile = this.tilesAround[side.ordinal()];
if (tile != null && provider.canShareTo(tile)) { if (tile != null && provider.canShareTo(tile)) {
WorldUtil.doEnergyInteraction(this, tile, side, amount); WorldUtil.doEnergyInteraction(this, tile, side, amount);
@ -249,14 +247,14 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
if (handler.doesShareFluid()) { if (handler.doesShareFluid()) {
int total = handler.getMaxFluidAmountToSplitShare(); int total = handler.getMaxFluidAmountToSplitShare();
if (total > 0) { if (total > 0) {
EnumFacing[] sides = handler.getFluidShareSides(); Direction[] sides = handler.getFluidShareSides();
int amount = total / sides.length; int amount = total / sides.length;
if (amount <= 0) { if (amount <= 0) {
amount = total; amount = total;
} }
for (EnumFacing side : sides) { for (Direction side : sides) {
TileEntity tile = this.tilesAround[side.ordinal()]; TileEntity tile = this.tilesAround[side.ordinal()];
if (tile != null) { if (tile != null) {
WorldUtil.doFluidInteraction(this, tile, side, amount); WorldUtil.doFluidInteraction(this, tile, side, amount);
@ -277,7 +275,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
} }
public void saveDataOnChangeOrWorldStart() { public void saveDataOnChangeOrWorldStart() {
for (EnumFacing side : EnumFacing.values()) { for (Direction side : Direction.values()) {
BlockPos pos = this.pos.offset(side); BlockPos pos = this.pos.offset(side);
if (this.world.isBlockLoaded(pos)) { if (this.world.isBlockLoaded(pos)) {
this.tilesAround[side.ordinal()] = this.world.getTileEntity(pos); this.tilesAround[side.ordinal()] = this.world.getTileEntity(pos);
@ -294,8 +292,8 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
this.markDirty(); this.markDirty();
} }
public boolean canPlayerUse(EntityPlayer player) { public boolean canPlayerUse(PlayerEntity player) {
return player.getDistanceSq(this.getPos().getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64 && !this.isInvalid() && this.world.getTileEntity(this.pos) == this; return player.getDistanceSq(this.getPos().getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64 && !this.isRemoved() && this.world.getTileEntity(this.pos) == this;
} }
protected boolean sendUpdateWithInterval() { protected boolean sendUpdateWithInterval() {
@ -307,36 +305,33 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
} }
} }
@Nonnull
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) { public <CAP> LazyOptional<CAP> getCapability(@Nonnull Capability<CAP> cap, @Nullable Direction side) {
return this.getCapability(capability, facing) != null; if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return this.getItemHandler(side).cast();
} }
@SuppressWarnings("unchecked") if (cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
@Override return this.getFluidHandler(side).cast();
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
IItemHandler handler = this.getItemHandler(facing);
if (handler != null) { return (T) handler; }
} else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
IFluidHandler tank = this.getFluidHandler(facing);
if (tank != null) { return (T) tank; }
} else if (capability == CapabilityEnergy.ENERGY) {
IEnergyStorage storage = this.getEnergyStorage(facing);
if (storage != null) { return (T) storage; }
}
return super.getCapability(capability, facing);
} }
public IFluidHandler getFluidHandler(EnumFacing facing) { if (cap == CapabilityEnergy.ENERGY) {
return this.getEnergyStorage(side).cast();
}
return super.getCapability(cap, side);
}
public LazyOptional<IFluidHandler> getFluidHandler(Direction facing) {
return null; return null;
} }
public IEnergyStorage getEnergyStorage(EnumFacing facing) { public LazyOptional<IEnergyStorage> getEnergyStorage(Direction facing) {
return null; return null;
} }
public IItemHandler getItemHandler(EnumFacing facing) { public LazyOptional<IItemHandler> getItemHandler(Direction facing) {
return null; return null;
} }

View file

@ -5,49 +5,54 @@ import de.ellpeck.actuallyadditions.common.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.common.util.ItemStackHandlerAA.IRemover; import de.ellpeck.actuallyadditions.common.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.common.util.StackUtil; import de.ellpeck.actuallyadditions.common.util.StackUtil;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.ListNBT;
import net.minecraft.util.EnumFacing; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
public abstract class TileEntityInventoryBase extends TileEntityBase { public abstract class TileEntityInventoryBase<T extends TileEntity> extends TileEntityBase {
public final ItemStackHandlerAA inv; public final ItemStackHandlerAA inv;
private final LazyOptional<ItemStackHandlerAA> lazyInv;
public TileEntityInventoryBase(int slots, String name) { public TileEntityInventoryBase(TileEntityType<T> type, int slots, String name) {
super(name); super(type, name);
this.inv = new TileStackHandler(slots); this.inv = new TileStackHandler(slots);
this.lazyInv = LazyOptional.of(() -> this.inv);
} }
public static void saveSlots(IItemHandler slots, NBTTagCompound compound) { public static void saveSlots(IItemHandler slots, CompoundNBT compound) {
if (slots != null && slots.getSlots() > 0) { if (slots != null && slots.getSlots() > 0) {
NBTTagList tagList = new NBTTagList(); ListNBT tagList = new ListNBT();
for (int i = 0; i < slots.getSlots(); i++) { for (int i = 0; i < slots.getSlots(); i++) {
ItemStack slot = slots.getStackInSlot(i); ItemStack slot = slots.getStackInSlot(i);
NBTTagCompound tagCompound = new NBTTagCompound(); CompoundNBT tagCompound = new CompoundNBT();
if (StackUtil.isValid(slot)) { if (StackUtil.isValid(slot)) {
slot.writeToNBT(tagCompound); slot.write(tagCompound);
} }
tagList.appendTag(tagCompound); tagList.add(tagCompound);
} }
compound.setTag("Items", tagList); compound.put("Items", tagList);
} }
} }
public static void loadSlots(IItemHandlerModifiable slots, NBTTagCompound compound) { public static void loadSlots(IItemHandlerModifiable slots, CompoundNBT compound) {
if (slots != null && slots.getSlots() > 0) { if (slots != null && slots.getSlots() > 0) {
NBTTagList tagList = compound.getTagList("Items", 10); ListNBT tagList = compound.getList("Items", 10);
for (int i = 0; i < slots.getSlots(); i++) { for (int i = 0; i < slots.getSlots(); i++) {
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); CompoundNBT tagCompound = tagList.getCompound(i);
slots.setStackInSlot(i, tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getEmpty()); slots.setStackInSlot(i, tagCompound.contains("id") ? ItemStack.read(tagCompound) : StackUtil.getEmpty());
} }
} }
} }
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
super.writeSyncableNBT(compound, type); super.writeSyncableNBT(compound, type);
if (type == NBTType.SAVE_TILE || type == NBTType.SYNC && this.shouldSyncSlots()) { if (type == NBTType.SAVE_TILE || type == NBTType.SYNC && this.shouldSyncSlots()) {
saveSlots(this.inv, compound); saveSlots(this.inv, compound);
@ -55,8 +60,8 @@ public abstract class TileEntityInventoryBase extends TileEntityBase {
} }
@Override @Override
public IItemHandler getItemHandler(EnumFacing facing) { public LazyOptional<ItemStackHandlerAA> getItemHandler(Direction facing) {
return this.inv; return this.lazyInv;
} }
public IAcceptor getAcceptor() { public IAcceptor getAcceptor() {
@ -90,7 +95,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase {
} }
@Override @Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type) { public void readSyncableNBT(CompoundNBT compound, NBTType type) {
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
if (type == NBTType.SAVE_TILE || type == NBTType.SYNC && this.shouldSyncSlots()) { if (type == NBTType.SAVE_TILE || type == NBTType.SYNC && this.shouldSyncSlots()) {
loadSlots(this.inv, compound); loadSlots(this.inv, compound);

View file

@ -1,33 +1,25 @@
package de.ellpeck.actuallyadditions.common.util; package de.ellpeck.actuallyadditions.common.util;
import java.util.ArrayList;
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.tile.FilterSettings; import de.ellpeck.actuallyadditions.common.tile.FilterSettings;
import de.ellpeck.actuallyadditions.common.util.compat.SlotlessableItemHandlerWrapper; import de.ellpeck.actuallyadditions.common.util.compat.SlotlessableItemHandlerWrapper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.SPacketBlockChange; import net.minecraft.item.Items;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -42,6 +34,8 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList;
public final class WorldUtil { public final class WorldUtil {
public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract) { public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract) {
@ -108,9 +102,9 @@ public final class WorldUtil {
return extracted; return extracted;
} }
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer) { public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
if (maxTransfer > 0) { if (maxTransfer > 0) {
EnumFacing opp = sideTo == null ? null : sideTo.getOpposite(); Direction opp = sideTo == null ? null : sideTo.getOpposite();
IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo); IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo);
IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp); IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp);
if (handlerFrom != null && handlerTo != null) { if (handlerFrom != null && handlerTo != null) {
@ -124,7 +118,7 @@ public final class WorldUtil {
} }
} }
public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer) { public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, Direction sideTo, int maxTransfer) {
if (maxTransfer > 0) { if (maxTransfer > 0) {
if (tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())) { if (tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())) {
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo); IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
@ -155,7 +149,7 @@ public final class WorldUtil {
return true; return true;
} }
public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack) { public static ItemStack useItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
if (world instanceof WorldServer && StackUtil.isValid(stack) && pos != null) { if (world instanceof WorldServer && StackUtil.isValid(stack) && pos != null) {
BlockPos offsetPos = pos.offset(side); BlockPos offsetPos = pos.offset(side);
IBlockState state = world.getBlockState(offsetPos); IBlockState state = world.getBlockState(offsetPos);
@ -192,7 +186,7 @@ public final class WorldUtil {
return stack; return stack;
} }
public static boolean dropItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack) { public static boolean dropItemAtSide(Direction side, World world, BlockPos pos, ItemStack stack) {
BlockPos coords = pos.offset(side); BlockPos coords = pos.offset(side);
if (world.isBlockLoaded(coords)) { if (world.isBlockLoaded(coords)) {
EntityItem item = new EntityItem(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack); EntityItem item = new EntityItem(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack);
@ -205,33 +199,33 @@ public final class WorldUtil {
return false; return false;
} }
public static EnumFacing getDirectionBySidesInOrder(int side) { public static Direction getDirectionBySidesInOrder(int side) {
switch (side) { switch (side) {
case 0: case 0:
return EnumFacing.UP; return Direction.UP;
case 1: case 1:
return EnumFacing.DOWN; return Direction.DOWN;
case 2: case 2:
return EnumFacing.NORTH; return Direction.NORTH;
case 3: case 3:
return EnumFacing.EAST; return Direction.EAST;
case 4: case 4:
return EnumFacing.SOUTH; return Direction.SOUTH;
default: default:
return EnumFacing.WEST; return Direction.WEST;
} }
} }
public static EnumFacing getDirectionByPistonRotation(IBlockState state) { public static Direction getDirectionByPistonRotation(IBlockState state) {
return state.getValue(BlockDirectional.FACING); return state.getValue(BlockDirectional.FACING);
} }
public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos) { public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos) {
ArrayList<Material> blocks = new ArrayList<>(); ArrayList<Material> blocks = new ArrayList<>();
blocks.add(world.getBlockState(pos.offset(EnumFacing.NORTH)).getMaterial()); blocks.add(world.getBlockState(pos.offset(Direction.NORTH)).getMaterial());
blocks.add(world.getBlockState(pos.offset(EnumFacing.EAST)).getMaterial()); blocks.add(world.getBlockState(pos.offset(Direction.EAST)).getMaterial());
blocks.add(world.getBlockState(pos.offset(EnumFacing.SOUTH)).getMaterial()); blocks.add(world.getBlockState(pos.offset(Direction.SOUTH)).getMaterial());
blocks.add(world.getBlockState(pos.offset(EnumFacing.WEST)).getMaterial()); blocks.add(world.getBlockState(pos.offset(Direction.WEST)).getMaterial());
return blocks; return blocks;
} }
@ -256,7 +250,7 @@ public final class WorldUtil {
return world.rayTraceBlocks(vec3, vec31, p1, p2, p3); return world.rayTraceBlocks(vec3, vec31, p1, p2, p3);
} }
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player) { public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, PlayerEntity player) {
return getNearestBlockWithDefaultReachDistance(world, player, false, true, false); return getNearestBlockWithDefaultReachDistance(world, player, false, true, false);
} }
@ -264,10 +258,10 @@ public final class WorldUtil {
return getMovingObjectPosWithReachDistance(world, player, player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock); return getMovingObjectPosWithReachDistance(world, player, player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
} }
public static void setHandItemWithoutAnnoyingSound(EntityPlayer player, EnumHand hand, ItemStack stack) { public static void setHandItemWithoutAnnoyingSound(PlayerEntity player, Hand hand, ItemStack stack) {
if (hand == EnumHand.MAIN_HAND) { if (hand == Hand.MAIN_HAND) {
player.inventory.mainInventory.set(player.inventory.currentItem, stack); player.inventory.mainInventory.set(player.inventory.currentItem, stack);
} else if (hand == EnumHand.OFF_HAND) { } else if (hand == Hand.OFF_HAND) {
player.inventory.offHandInventory.set(0, stack); player.inventory.offHandInventory.set(0, stack);
} }
} }
@ -294,18 +288,18 @@ public final class WorldUtil {
* @param pos The pos to break. * @param pos The pos to break.
* @return If the break was successful. * @return If the break was successful.
*/ */
public static boolean breakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos) { public static boolean breakExtraBlock(ItemStack stack, World world, PlayerEntity player, BlockPos pos) {
IBlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if (player.capabilities.isCreativeMode) { if (player.isCreative()) {
if (block.removedByPlayer(state, world, pos, player, false)) { if (block.removedByPlayer(state, world, pos, player, false, world.getFluidState(pos))) {
block.onPlayerDestroy(world, pos, state); block.onPlayerDestroy(world, pos, state);
} }
// send update to client // send update to client
if (!world.isRemote) { if (!world.isRemote) {
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos)); ((ServerPlayerEntity) player).connection.sendPacket(new SPacketBlockChange(world, pos));
} }
return true; return true;
} }
@ -316,18 +310,18 @@ public final class WorldUtil {
// server sided handling // server sided handling
if (!world.isRemote) { if (!world.isRemote) {
// send the blockbreak event // send the blockbreak event
int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos); int xp = ForgeHooks.onBlockBreakEvent(world, ((ServerPlayerEntity) player).interactionManager.getGameType(), (ServerPlayerEntity) player, pos);
if (xp == -1) return false; if (xp == -1) return false;
TileEntity tileEntity = world.getTileEntity(pos); TileEntity tileEntity = world.getTileEntity(pos);
if (block.removedByPlayer(state, world, pos, player, true)) { // boolean is if block can be harvested, checked above if (block.removedByPlayer(state, world, pos, player, true, world.getFluidState(pos))) { // boolean is if block can be harvested, checked above
block.onPlayerDestroy(world, pos, state); block.onPlayerDestroy(world, pos, state);
block.harvestBlock(world, player, pos, state, tileEntity, stack); block.harvestBlock(world, player, pos, state, tileEntity, stack);
block.dropXpOnBlockBreak(world, pos, xp); block.dropXpOnBlockBreak(world, pos, xp);
} }
// always send block update to client // always send block update to client
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos)); ((ServerPlayerEntity) player).connection.sendPacket(new SPacketBlockChange(world, pos));
return true; return true;
} }
// client sided handling // client sided handling
@ -337,7 +331,7 @@ public final class WorldUtil {
// following code can be found in PlayerControllerMP.onPlayerDestroyBlock // following code can be found in PlayerControllerMP.onPlayerDestroyBlock
world.playEvent(2001, pos, Block.getStateId(state)); world.playEvent(2001, pos, Block.getStateId(state));
if (block.removedByPlayer(state, world, pos, player, true)) { if (block.removedByPlayer(state, world, pos, player, true, world.getFluidState(pos))) {
block.onPlayerDestroy(world, pos, state); block.onPlayerDestroy(world, pos, state);
} }
// callback to the tool // callback to the tool