Skip to content

AE2 integrated optimization #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master-1.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}