diff --git a/src/main/java/micdoodle8/mods/galacticraft/core/blocks/BlockEnclosed.java b/src/main/java/micdoodle8/mods/galacticraft/core/blocks/BlockEnclosed.java index 1cdfc2953d..d5d1a2cf81 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/core/blocks/BlockEnclosed.java +++ b/src/main/java/micdoodle8/mods/galacticraft/core/blocks/BlockEnclosed.java @@ -11,6 +11,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; +import appeng.tile.networking.TileCableBus; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; @@ -387,23 +388,12 @@ public TileEntity createNewTileEntity(World world, int metadata) { if (CompatibilityManager.isAppEngLoaded()) { - // Emulate Api.INSTANCE.partHelper().getCombinedInstance( - // TileCableBus.class ) - try - { - IPartHelper apiPart = AEApi.instance().partHelper(); - Class classTileCableBus = Class.forName("appeng.tile.networking.TileCableBus"); - for (Method m : apiPart.getClass().getMethods()) - { - if ("getCombinedInstance".equals(m.getName())) - { - return (TileEntity) ((Class) m.invoke(apiPart, classTileCableBus)).newInstance(); - } - } - } catch (Exception e) - { - e.printStackTrace(); - } + try { + Class cableBusClass = Class.forName("appeng.tile.networking.TileCableBus"); + return (TileEntity) cableBusClass.newInstance(); + }catch (Exception e){ + GalacticraftCore.logger.catching(e); + } } } else if (metadata <= EnumEnclosedBlockType.ALUMINUM_WIRE.getMeta()) { diff --git a/src/main/java/micdoodle8/mods/galacticraft/core/items/ItemBlockEnclosed.java b/src/main/java/micdoodle8/mods/galacticraft/core/items/ItemBlockEnclosed.java index bd8ea05a84..e432d362de 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/core/items/ItemBlockEnclosed.java +++ b/src/main/java/micdoodle8/mods/galacticraft/core/items/ItemBlockEnclosed.java @@ -9,6 +9,9 @@ import java.lang.reflect.Method; +import appeng.container.slot.SlotRestrictedInput; +import appeng.parts.PartPlacement; +import micdoodle8.mods.galacticraft.core.GalacticraftCore; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; @@ -29,99 +32,72 @@ import appeng.api.AEApi; import appeng.api.util.AEColor; -public class ItemBlockEnclosed extends ItemBlockDesc implements GCRarity -{ - - public ItemBlockEnclosed(Block block) - { - super(block); - this.setMaxDamage(0); - this.setHasSubtypes(true); - } - - @Override - public String getTranslationKey(ItemStack par1ItemStack) - { - String name; - - try - { - name = BlockEnclosed.EnumEnclosedBlockType.byMetadata(par1ItemStack.getItemDamage()).getName(); - name = name.substring(9, name.length()); // Remove "enclosed_" - } catch (Exception e) - { - name = "null"; - } - - return this.getBlock().getTranslationKey() + "." + name; - } - - @Override - public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) - { - ItemStack itemstack = playerIn.getHeldItem(hand); - int metadata = this.getMetadata(itemstack.getItemDamage()); - if (metadata == EnumEnclosedBlockType.ME_CABLE.getMeta() && CompatibilityManager.isAppEngLoaded()) - { - IBlockState iblockstate = worldIn.getBlockState(pos); - Block block = iblockstate.getBlock(); - BlockPos origPos = pos; - - if (!block.isReplaceable(worldIn, pos)) - { - pos = pos.offset(side); - } - - if (itemstack.getCount() == 0) - { - return EnumActionResult.FAIL; - } else if (!playerIn.canPlayerEdit(pos, side, itemstack)) - { - return EnumActionResult.FAIL; - } else if (worldIn.mayPlace(this.block, pos, false, side, null)) - { - int i = this.getMetadata(itemstack.getMetadata()); - IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn); - - if (placeBlockAt(itemstack, playerIn, worldIn, pos, side, hitX, hitY, hitZ, iblockstate1)) - { - SoundType soundType = this.getBlock().getSoundType(iblockstate, worldIn, pos, playerIn); - worldIn.playSound(playerIn, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, - soundType.getPitch() * 0.8F); - itemstack.shrink(1); - - ItemStack itemME = AEApi.instance().definitions().parts().cableGlass().stack(AEColor.TRANSPARENT, 1); - itemME.setCount(2); // Fool AppEng into not destroying - // anything in the player inventory - AEApi.instance().partHelper().placeBus(itemME, origPos, side, playerIn, hand, worldIn); - // Emulate appeng.parts.PartPlacement.place( is, pos, side, - // player, w, PartPlacement.PlaceType.INTERACT_SECOND_PASS, - // 0 ); - try - { - Class clazzpp = Class.forName("appeng.parts.PartPlacement"); - Class enumPlaceType = Class.forName("appeng.parts.PartPlacement$PlaceType"); - Method methPl = clazzpp.getMethod("place", ItemStack.class, BlockPos.class, EnumFacing.class, EntityPlayer.class, EnumHand.class, World.class, enumPlaceType, int.class); - methPl.invoke(null, itemME, origPos, side, playerIn, hand, worldIn, enumPlaceType.getEnumConstants()[2], 0); - } catch (Exception e) - { - e.printStackTrace(); - } - } - return EnumActionResult.SUCCESS; - } else - { - return EnumActionResult.FAIL; - } - } else - { - return super.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ); - } - } - - @Override - public int getMetadata(int damage) - { - return damage; - } +public class ItemBlockEnclosed extends ItemBlockDesc implements GCRarity { + + public ItemBlockEnclosed(Block block) { + super(block); + this.setMaxDamage(0); + this.setHasSubtypes(true); + } + + @Override + public String getTranslationKey(ItemStack par1ItemStack) { + String name; + + try { + name = BlockEnclosed.EnumEnclosedBlockType.byMetadata(par1ItemStack.getItemDamage()).getName(); + name = name.substring(9, name.length()); // Remove "enclosed_" + } catch (Exception e) { + name = "null"; + } + + return this.getBlock().getTranslationKey() + "." + name; + } + + @Override + public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { + ItemStack itemstack = playerIn.getHeldItem(hand); + int metadata = this.getMetadata(itemstack.getItemDamage()); + if (metadata == EnumEnclosedBlockType.ME_CABLE.getMeta() && CompatibilityManager.isAppEngLoaded()) { + IBlockState iblockstate = worldIn.getBlockState(pos); + Block block = iblockstate.getBlock(); + BlockPos origPos = pos; + + if (!block.isReplaceable(worldIn, pos)) { + pos = pos.offset(side); + } + + if (itemstack.getCount() == 0) { + return EnumActionResult.FAIL; + } else if (!playerIn.canPlayerEdit(pos, side, itemstack)) { + return EnumActionResult.FAIL; + } else if (worldIn.mayPlace(this.block, pos, false, side, null)) { + int i = this.getMetadata(itemstack.getMetadata()); + IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn); + + if (placeBlockAt(itemstack, playerIn, worldIn, pos, side, hitX, hitY, hitZ, iblockstate1)) { + itemstack.shrink(1); + + ItemStack itemME = AEApi.instance().definitions().parts().cableGlass().stack(AEColor.TRANSPARENT, 1); + itemME.setCount(2); // Fool AppEng into not destroying + // anything in the player inventory + AEApi.instance().partHelper().placeBus(itemME, origPos, side, playerIn, hand, worldIn); + } + return EnumActionResult.SUCCESS; + } else { + return EnumActionResult.FAIL; + } + } else { + return super.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ); + } + } + + + + + + @Override + public int getMetadata(int damage) { + return damage; + } }