diff --git a/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java b/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java index 9af4dfa..f07fc95 100644 --- a/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java +++ b/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java @@ -56,6 +56,7 @@ import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; +import appeng.api.parts.BusSupport; import appeng.api.parts.IPartCollisionHelper; import appeng.api.parts.IPartRenderHelper; import appeng.api.storage.IExternalStorageHandler; @@ -1046,4 +1047,5 @@ public void validateLink() { * return null; * } */ + } diff --git a/src/main/java/reobf/proghatches/ae/PartStockingExportBus.java b/src/main/java/reobf/proghatches/ae/PartStockingExportBus.java index 3bbe17a..038919f 100644 --- a/src/main/java/reobf/proghatches/ae/PartStockingExportBus.java +++ b/src/main/java/reobf/proghatches/ae/PartStockingExportBus.java @@ -264,6 +264,7 @@ public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) Actionable.SIMULATE, this.mySrc); if (itemsToAdd == null) break; + itemsToAdd.setCraftable(false); this.pushItemIntoTarget(destination, energy, inv, itemsToAdd); if (itemToSend <= 0) break; diff --git a/src/main/java/reobf/proghatches/ae/PartStockingFluidExportBus.java b/src/main/java/reobf/proghatches/ae/PartStockingFluidExportBus.java index dacdba9..dd64ef3 100644 --- a/src/main/java/reobf/proghatches/ae/PartStockingFluidExportBus.java +++ b/src/main/java/reobf/proghatches/ae/PartStockingFluidExportBus.java @@ -245,6 +245,7 @@ public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) Actionable.SIMULATE, this.mySrc); if (itemsToAdd == null) break; + itemsToAdd.setCraftable(false); // long before=itemToSend; this.pushItemIntoTarget(te, energy, inv, itemsToAdd); // if(before==itemToSend)break; diff --git a/src/main/java/reobf/proghatches/ae/part2/ItemPartCoW.java b/src/main/java/reobf/proghatches/ae/part2/ItemPartCoW.java new file mode 100644 index 0000000..80133e8 --- /dev/null +++ b/src/main/java/reobf/proghatches/ae/part2/ItemPartCoW.java @@ -0,0 +1,112 @@ +package reobf.proghatches.ae.part2; + +import java.util.List; + +import javax.annotation.Nullable; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import appeng.api.AEApi; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartItem; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemPartCoW extends Item implements IPartItem { + + @SideOnly(Side.CLIENT) + private IIcon icon; + + public ItemPartCoW() { + this.setMaxStackSize(64); + + AEApi.instance() + .partHelper() + .setItemBusRenderer(this); + setHasSubtypes(true); + } + + @Nullable + @Override + public IPart createPartFromItemStack(ItemStack is) { + return new PartCoW(is); + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + /* + * int damage=stack.getItemDamage(); + * if(damage>=1&&damage<=15){ + * return + * StatCollector.translateToLocalFormatted("item.proghatches.part.eu.source.superconduct.name",GTValues.VN[ + * damage-1]); + * } + * if(damage>=16&&damage<=30){ + * return + * StatCollector.translateToLocalFormatted("item.proghatches.part.eu.source.normal.name",GTValues.VN[damage-16]) + * ; + * } + */ + return super.getItemStackDisplayName(stack); + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, + float xOffset, float yOffset, float zOffset) { + return AEApi.instance() + .partHelper() + .placeBus(player.getHeldItem(), x, y, z, side, player, world); + } + + /* + * public ItemPartEUSource register() { //if (!Config.fluidIOBus) return + * null; GameRegistry.registerItem(this, NameConst.ITEM_PART_FLUID_EXPORT, + * FluidCraft.MODID); //setCreativeTab(FluidCraftingTabs.INSTANCE); return + * this; } + */ + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IIconRegister register) { + + this.icon = register.registerIcon("proghatches:cow"); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIconFromDamage(int dmg) { + return icon; + } + + /* + * @Override + * public IIcon getIconIndex(ItemStack p_77650_1_) { + * return PartEUSource.a; + * } + */ + @Override + @SideOnly(Side.CLIENT) + public int getSpriteNumber() { + return 0; + } + + @SideOnly(value = Side.CLIENT) + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { + p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.cow.tooltips.0")); + p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.cow.tooltips.1")); + p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.cow.tooltips.2")); + p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.cow.tooltips.3")); + p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.cow.tooltips.4")); + // p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.ma.p2p.tooltips.1")); + // p_77624_3_.add(StatCollector.translateToLocal("item.proghatches.part.ma.p2p.tooltips.2")); + // + super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); + } + +} diff --git a/src/main/java/reobf/proghatches/ae/part2/PartCoW.java b/src/main/java/reobf/proghatches/ae/part2/PartCoW.java new file mode 100644 index 0000000..dd4061e --- /dev/null +++ b/src/main/java/reobf/proghatches/ae/part2/PartCoW.java @@ -0,0 +1,509 @@ +package reobf.proghatches.ae.part2; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Deque; +import java.util.List; +import java.util.NavigableMap; +import java.util.TreeMap; + +import com.google.common.base.Optional; + +import appeng.api.AEApi; +import appeng.api.config.TunnelType; +import appeng.api.definitions.IParts; +import appeng.api.exceptions.FailedConnection; +import appeng.api.implementations.IPowerChannelState; +import appeng.api.implementations.items.IMemoryCard; +import appeng.api.implementations.items.MemoryCardMessages; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.api.parts.BusSupport; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartItem; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.parts.PartItemStack; +import appeng.client.texture.CableBusTextures; +import appeng.me.GridAccessException; +import appeng.me.GridConnection; +import appeng.me.helpers.AENetworkProxy; +import appeng.parts.PartBasicState; +import appeng.parts.p2p.IPartGT5Power; +import appeng.parts.p2p.PartP2PTunnel; +import appeng.parts.p2p.PartP2PTunnelNormal; +import appeng.tile.networking.TileCableBus; +import appeng.util.item.AEItemStack; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.graphs.GenerateNodeMap; +import gregtech.api.graphs.GenerateNodeMapPower; +import gregtech.api.graphs.Node; +import gregtech.api.graphs.PowerNode; +import gregtech.api.graphs.consumers.ConsumerNode; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.implementations.MTECable; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.fluids.FluidStack; +import reobf.proghatches.fmp.IUpdatable; + +public class PartCoW extends PartBasicState implements IGridTickable, IPartGT5Power, IPowerChannelState,IUpdatable { + + public PartCoW(ItemStack is) { + super(is); + this.proxy.setFlags(GridFlags.DENSE_CAPACITY);// no channel + setInWorld(this.proxy); + } + + Field f; + + public void setInWorld(AENetworkProxy w) { + + try { + + if (f == null) { + f = w.getClass().getDeclaredField("worldNode"); + f.setAccessible(true); + Field modifiers = f.getClass().getDeclaredField("modifiers"); + modifiers.setAccessible(true); + modifiers.setInt(f, f.getModifiers() & ~Modifier.FINAL); + } + + f.set(w, true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public AENetworkProxy getProxy() { + // TODO Auto-generated method stub + return super.getProxy(); + } + + @Override + public TickingRequest getTickingRequest(IGridNode node) { + + return new TickingRequest(1, 1, false, false); + } + + public MTECable get() { + TileEntity te = this.host.getTile().getWorldObj().getTileEntity(this.host.getLocation().x + this.side.offsetX, + this.host.getLocation().y + this.side.offsetY, this.host.getLocation().z + this.side.offsetZ); + if (te instanceof IGregTechTileEntity) { + IGregTechTileEntity gte = (IGregTechTileEntity) te; + IMetaTileEntity mte = gte.getMetaTileEntity(); + if (mte instanceof MTECable) { + MTECable c = (MTECable) mte; + // final BaseMetaPipeEntity tBase = (BaseMetaPipeEntity) + // c.getBaseMetaTileEntity(); + return c; + } + + } + return null; + + } + + int count; + + @Override + public void onNeighborChanged() { + MTECable c = get(); + if (c != null) { + if(!c.isConnectedAtSide(this.side.getOpposite())){return;} + // cannot wait for 20tick to setup! we need it built instantly + final int time = MinecraftServer.getServer().getTickCounter(); + BaseMetaPipeEntity pipe = (((BaseMetaPipeEntity) c.getBaseMetaTileEntity())); + final Node node = pipe.getNode(); + if (node == null) { + new GenerateNodeMapPower(pipe); + } else if (node.mCreationTime != time) { + GenerateNodeMap.clearNodeMap(node, -1); + new GenerateNodeMapPower(pipe); + } + } + } + + long channel; + CoWGridConnection connection; + + public class CoWGridConnection extends GridConnection { + + public CoWGridConnection(IGridNode aNode, IGridNode bNode, ForgeDirection fromAtoB) throws FailedConnection { + super(aNode, bNode, fromAtoB); + } + + public boolean destroyed; + + @Override + public void destroy() { + destroyed = true; + super.destroy(); + } + + } + + @Override + public TickRateModulation tickingRequest(IGridNode nodexx, int TicksSinceLastCallxx) { + count++; + boolean thisTick=(update&1)!=0; + update=update>>1; + if(thisTick){ + onNeighborChanged(); + + } + + + if (count < 3) { + onNeighborChanged(); + } + if (count % 20 != 5) + return TickRateModulation.SAME; + updateConn(); + + return TickRateModulation.SAME; + } + + public void updateConn() { + MTECable c = get(); + if (c != null&&c.isConnectedAtSide(this.getSide().getOpposite())) { + BaseMetaPipeEntity pipe = (((BaseMetaPipeEntity) c.getBaseMetaTileEntity())); + ArrayList list = new ArrayList<>(); + final Node node = pipe.getNode(); + if (node != null) + for (ConsumerNode n : node.mConsumers) { + + TileEntity te = (n.mTileEntity); + if (te instanceof TileCableBus) { + TileCableBus cable = (TileCableBus) te; + IPart pt = cable.getPart(n.mSide); + if (pt instanceof PartCoW && pt != this) { + if (((PartCoW) pt).channel == this.channel && channel != 0) + list.add((PartCoW) pt); + } + // System.out.println(pt); + } + } + + PartCoW other = null; + if (connection != null) { + if (connection.destroyed) { + connection = null; + } + + } + + if (connection != null) { + other = (PartCoW) connection.getOtherSide(this.getGridNode()).getMachine(); + boolean shouldDestroy = false; + if (list.size() > 1) { + shouldDestroy = true; + } else if (list.size() == 0) { + shouldDestroy = true; + } else if (channel == 0) + shouldDestroy = true; + else if (other != null && other.channel == 0) + shouldDestroy = true; + else if (other != null && other.channel != channel) + shouldDestroy = true; + + if (shouldDestroy) { + connection.destroy(); + connection = null; + other.connection = null; + } + + } + if (list.size() > 1) { + securityBreak(); + } + if (list.size() == 1 && connection == null) { + + try { + connection = new CoWGridConnection(this.getGridNode(), list.get(0).getGridNode(), + ForgeDirection.UNKNOWN); + list.get(0).connection=connection; + + } catch (FailedConnection e) { + + } catch (Exception e) { + e.printStackTrace(); + + } + } + + /* + * if(list.size()==0){ if(connection!=null){ PartCoW other=(PartCoW) + * connection.getOtherSide(this.getGridNode()).getMachine(); + * other.connection=null; connection=null; connection.destroy(); } } + */ + + }else{ + + if(connection!=null){ + PartCoW other = (PartCoW) connection.getOtherSide(this.getGridNode()).getMachine(); + connection.destroy(); + connection = null; + other.connection = null; + + } + } + + } + + @Override + public boolean canBePlacedOn(BusSupport what) { + + return what != BusSupport.NO_PARTS; + } + + @Override + public long injectEnergyUnits(long voltage, long amperage) { + + return 0; + } + + @Override + public boolean inputEnergy() { + + return true; + } + + @Override + public boolean outputsEnergy() { + + return false; + } + + public boolean useStandardMemoryCard() { + return false; + } + + @Override + public boolean onPartShiftActivate(final EntityPlayer player, final Vec3 pos) { + final ItemStack is = player.inventory.getCurrentItem(); + if (is != null && is.getItem() instanceof IMemoryCard) { + IMemoryCard mc = (IMemoryCard) is.getItem(); + if (ForgeEventFactory.onItemUseStart(player, is, 1) <= 0) + return false; + + if (channel == 0) { + channel = System.currentTimeMillis(); + } + + final NBTTagCompound data = this.getMemoryCardData(); + final ItemStack p2pItem = this.getItemStack(PartItemStack.Wrench); + final String type = p2pItem.getUnlocalizedName(); + + p2pItem.writeToNBT(data); + + mc.setMemoryCardContents(is, type + ".name", data); + mc.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED); + return true; + } + return false; + } + + @Override + public boolean onPartActivate(final EntityPlayer player, final Vec3 pos) { + final ItemStack is = player.inventory.getCurrentItem(); + + // UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( + // is.getItem() ); + // AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() ); + + // final TunnelType tt = + // AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem(is); + if (is != null && is.getItem() instanceof IMemoryCard) { + IMemoryCard mc = (IMemoryCard) is.getItem(); + if (ForgeEventFactory.onItemUseStart(player, is, 1) <= 0) + return false; + + final NBTTagCompound data = mc.getData(is); + + final ItemStack newType = ItemStack.loadItemStackFromNBT(data); + final long freq = data.getLong("freq"); + + if (newType != null) { + if (newType.getItem() instanceof IPartItem) { + final IPart testPart = ((IPartItem) newType.getItem()).createPartFromItemStack(newType); + if (testPart instanceof PartCoW) { + this.getHost().removePart(this.getSide(), true); + final ForgeDirection dir = this.getHost().addPart(newType, this.getSide(), player); + final IPart newBus = this.getHost().getPart(dir); + + if (newBus instanceof PartCoW) { + PartCoW newTunnel = (PartCoW) newBus; + + newTunnel.channel = freq; + updateConn(); + } + + mc.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED); + return true; + } + } + } + mc.notifyUser(player, MemoryCardMessages.INVALID_MACHINE); + } + + return false; + } + + public NBTTagCompound getMemoryCardData() { + final NBTTagCompound output = new NBTTagCompound(); + + if (this.hasCustomName()) { + final NBTTagCompound dsp = new NBTTagCompound(); + dsp.setString("Name", this.getCustomName()); + output.setTag("display", dsp); + } + output.setLong("freq", channel); + + return output; + } + + @Override + public void getBoxes(final IPartCollisionHelper bch) { + bch.addBox(5, 5, 12, 11, 11, 13); + bch.addBox(3, 3, 13, 13, 13, 14); + bch.addBox(2, 2, 14, 14, 14, 16); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { + rh.setTexture(this.getTypeTexture()); + + rh.setBounds(2, 2, 14, 14, 14, 16); + rh.renderInventoryBox(renderer); + + rh.setTexture(CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), + CableBusTextures.BlockP2PTunnel2.getIcon(), this.getItemStack().getIconIndex(), + CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon()); + + rh.setBounds(2, 2, 14, 14, 14, 16); + rh.renderInventoryBox(renderer); + } + + /** + * @return If enabled it returns the icon of an AE quartz block, else + * vanilla quartz block icon + */ + public IIcon getTypeTexture() { + final Optional maybeBlock = AEApi.instance().definitions().blocks().quartz().maybeBlock(); + if (maybeBlock.isPresent()) { + return maybeBlock.get().getIcon(0, 0); + } else { + return Blocks.quartz_block.getIcon(0, 0); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh, + final RenderBlocks renderer) { + this.setRenderCache(rh.useSimplifiedRendering(x, y, z, this, this.getRenderCache())); + rh.setTexture(this.getTypeTexture()); + + rh.setBounds(2, 2, 14, 14, 14, 16); + rh.renderBlock(x, y, z, renderer); + + rh.setTexture(CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), + CableBusTextures.BlockP2PTunnel2.getIcon(), this.getItemStack().getIconIndex(), + CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon()); + + rh.setBounds(2, 2, 14, 14, 14, 16); + rh.renderBlock(x, y, z, renderer); + + rh.setBounds(3, 3, 13, 13, 13, 14); + rh.renderBlock(x, y, z, renderer); + + rh.setTexture(CableBusTextures.BlockP2PTunnel3.getIcon()); + + rh.setBounds(6, 5, 12, 10, 11, 13); + rh.renderBlock(x, y, z, renderer); + + rh.setBounds(5, 6, 12, 11, 10, 13); + rh.renderBlock(x, y, z, renderer); + + this.renderLights(x, y, z, rh, renderer); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + data.setLong("channel", channel); + super.writeToNBT(data); + } + + @Override + public void readFromNBT(NBTTagCompound data) { + channel = data.getLong("channel"); + super.readFromNBT(data); + } + + public static class WailaDataProvider extends appeng.integration.modules.waila.part.BasePartWailaDataProvider { + + @Override + public List getWailaBody(IPart part, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + if (!(part instanceof PartCoW)) { + return currenttip; + } + try { + + final String freqTooltip = String.format("%X", accessor.getNBTData().getLong("channel")) + .replaceAll("(.{4})", "$0 ").trim(); + + currenttip.add("frequency:" + freqTooltip); + return currenttip; + } catch (Exception e) { + e.printStackTrace(); + } + return currenttip; + } + + @Override + public NBTTagCompound getNBTData(EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound data, + World world, int x, int y, int z) { + + if (!(part instanceof PartCoW)) { + return data; + } + PartCoW thiz = (PartCoW) part; + data.setLong("channel", thiz.channel); + return data; + } + + } + int update; + public void update() { + update=update|0x1010;//update after 4 ticks and 12 ticks + + } + +} diff --git a/src/main/java/reobf/proghatches/fmp/IUpdatable.java b/src/main/java/reobf/proghatches/fmp/IUpdatable.java new file mode 100644 index 0000000..d830863 --- /dev/null +++ b/src/main/java/reobf/proghatches/fmp/IUpdatable.java @@ -0,0 +1,5 @@ +package reobf.proghatches.fmp; + +public interface IUpdatable { + public void update(); +} diff --git a/src/main/java/reobf/proghatches/fmp/LayerUpdatable.java b/src/main/java/reobf/proghatches/fmp/LayerUpdatable.java new file mode 100644 index 0000000..6cd879d --- /dev/null +++ b/src/main/java/reobf/proghatches/fmp/LayerUpdatable.java @@ -0,0 +1,38 @@ +package reobf.proghatches.fmp; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.ae.part2.PartCoW; +import appeng.api.implementations.tiles.ICraftingMachine; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.parts.IPart; +import appeng.api.parts.LayerBase; +import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; + +public class LayerUpdatable extends LayerBase implements IMachineBlockUpdateable { + + @Override + public void onMachineBlockUpdate() { + + + for(ForgeDirection side:ForgeDirection.VALID_DIRECTIONS){ + + IPart pt = this.getPart(side); + if(pt instanceof IUpdatable){ + + IUpdatable cw=(IUpdatable) pt; + cw.update(); + + } + } + + + } +@Override +public boolean isMachineBlockUpdateRecursive() { + + return false; +} + + +} diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java b/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java index 54ff510..7eb240f 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java @@ -75,6 +75,7 @@ import appeng.api.implementations.IPowerChannelState; import appeng.api.networking.GridFlags; import appeng.api.networking.IGridNode; +import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.IActionHost; import appeng.api.networking.security.MachineSource; import appeng.api.storage.IMEMonitor; @@ -126,6 +127,7 @@ import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -135,6 +137,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; @@ -208,7 +211,7 @@ public ItemStack updateInformationSlot(int aIndex, ItemStack aStack) { IMEMonitor sg = proxy.getStorage().getItemInventory(); IAEItemStack request = AEItemStack.create(i_mark[aIndex]); request.setStackSize(Long.MAX_VALUE); - IAEItemStack result = sg.extractItems(request, Actionable.SIMULATE, source); + IAEItemStack result = sg.extractItems(request, Actionable.SIMULATE, getRequestSource()); ItemStack s = (result != null) ? result.getItemStack() : null; if(result!=null){ ItemStackG g=ItemStackG.fromAE(result, intmaxs); @@ -251,7 +254,7 @@ public void updateInformationSlotF(int index) { IMEMonitor sg = proxy.getStorage().getFluidInventory(); IAEFluidStack request = AEFluidStack.create(fluidStack); request.setStackSize(Long.MAX_VALUE); - IAEFluidStack result = sg.extractItems(request, Actionable.SIMULATE, source); + IAEFluidStack result = sg.extractItems(request, Actionable.SIMULATE, getRequestSource()); if(result!=null){ FluidTankG g=new FluidTankG(); g.fromAE(result, intmaxs); @@ -303,6 +306,7 @@ public Integer get() { @Override public void addUIWidgets(Builder builder, UIBuildContext buildContext) { + updateAllInformationSlots(); final SlotWidget[] aeSlotWidgets = new SlotWidget[16]; builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); @@ -376,8 +380,11 @@ protected void drawSlot(Slot slotIn) { AppEngRenderItem.POST_HOOKS.add(HookHolder.SKIP_ITEM_STACK_SIZE_HOOK); final RenderItem pIR = this.setItemRender(aeRenderItem); try { - aeRenderItem.setAeStack(Platform.getAEStackInSlot(slotIn).setStackSize(i_client[slotIn.getSlotIndex()])); - drawSlot(slotIn, true); + IAEItemStack is = Platform.getAEStackInSlot(slotIn); + if(is!=null){is.setStackSize(i_client[slotIn.getSlotIndex()]);} + aeRenderItem.setAeStack(is); + + drawSlot(slotIn, true); } catch (final Exception err) { AELog.warn("[AppEng] AE prevented crash while drawing slot: " + err); } @@ -856,7 +863,7 @@ public void program() { for (IAEItemStack s : getProxy().getStorage().getItemInventory().getStorageList()) { IAEItemStack ext = getProxy().getStorage().getItemInventory().extractItems(s, Actionable.MODULATE, - source); + getRequestSource()); if (ext != null && ext.getStackSize() > 0) { ItemStack item = ext.getItemStack(); item.stackSize = 0; @@ -880,8 +887,11 @@ public void program() { } catch (GridAccessException e) { } } - - MachineSource source = new MachineSource(((IActionHost) getBaseMetaTileEntity())); + private BaseActionSource getRequestSource() { + if (requestSource == null) requestSource = new MachineSource((IActionHost) getBaseMetaTileEntity()); + return requestSource; + } + MachineSource requestSource ;//= new MachineSource(((IActionHost) getBaseMetaTileEntity())); boolean recipe; int intmaxs = 3; @@ -895,8 +905,10 @@ public void startRecipeProcessing() { if (i_mark[i] != null) { try { - IAEItemStack possible = getProxy().getStorage().getItemInventory().extractItems( - AEItemStack.create(i_mark[i]).setStackSize(Long.MAX_VALUE), Actionable.SIMULATE, source); + IAEItemStack possible=null; + if(i_mark[i]!=null) + possible= getProxy().getStorage().getItemInventory().extractItems( + AEItemStack.create(i_mark[i]).setStackSize(Long.MAX_VALUE), Actionable.SIMULATE, getRequestSource()); i_shadow[i] = possible == null ? null : ItemStackG.fromAE(possible, intmaxs); if (i_shadow[i] != null) i_saved[i] = i_shadow[i].stackSize(); @@ -911,8 +923,10 @@ public void startRecipeProcessing() { if (f_mark[i] != null) { try { - IAEFluidStack possible = getProxy().getStorage().getFluidInventory().extractItems( - AEFluidStack.create(f_mark[i]).setStackSize(Long.MAX_VALUE), Actionable.SIMULATE, source); + IAEFluidStack possible=null; + if(f_mark[i]!=null) + possible= getProxy().getStorage().getFluidInventory().extractItems( + AEFluidStack.create(f_mark[i]).setStackSize(Long.MAX_VALUE), Actionable.SIMULATE, getRequestSource()); f_shadow[i].fromAE(possible, intmaxs); if (f_shadow[i] != null) f_saved[i] = f_shadow[i].getFluidAmount(); @@ -945,7 +959,7 @@ public CheckRecipeResult endRecipeProcessing(MTEMultiBlockBase controller) { IAEItemStack toextract = AEItemStack.create(i_mark[i]).setStackSize(delta); try { IAEItemStack get = getProxy().getStorage().getItemInventory().extractItems(toextract, - Actionable.MODULATE, source); + Actionable.MODULATE, getRequestSource()); if (get == null || get.getStackSize() != get.getStackSize()) { MyMod.LOG.fatal("cannot extract!"); controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); @@ -980,7 +994,7 @@ public CheckRecipeResult endRecipeProcessing(MTEMultiBlockBase controller) { IAEFluidStack toextract = AEFluidStack.create(f_mark[i]).setStackSize(delta); try { IAEFluidStack get = getProxy().getStorage().getFluidInventory().extractItems(toextract, - Actionable.MODULATE, source); + Actionable.MODULATE, getRequestSource()); if (get == null || get.getStackSize() != get.getStackSize()) { MyMod.LOG.fatal("cannot extract!"); controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); @@ -1171,7 +1185,8 @@ protected void updateValidGridProxySides() { } @Override - public void saveNBTData(NBTTagCompound aNBT) { + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("additionalConnection", additionalConnection); aNBT.setBoolean("allowAuto", allowAuto); getProxy().writeToNBT(aNBT); super.saveNBTData(aNBT); @@ -1179,6 +1194,7 @@ public void saveNBTData(NBTTagCompound aNBT) { for (int i = 0; i < 16; i++) { FluidStack fluidStack = f_mark[i]; if (fluidStack == null) { + nbtTagList.appendTag(new NBTTagCompound()); continue; } NBTTagCompound fluidTag = fluidStack.writeToNBT(new NBTTagCompound()); @@ -1192,6 +1208,7 @@ public void saveNBTData(NBTTagCompound aNBT) { for (int i = 0; i < 16; i++) { ItemStack fluidStack = i_mark[i]; if (fluidStack == null) { + nbtTagList.appendTag(new NBTTagCompound()); continue; } NBTTagCompound fluidTag = fluidStack.writeToNBT(new NBTTagCompound()); @@ -1239,7 +1256,7 @@ public void saveNBTData(NBTTagCompound aNBT) { } @Override - public void loadNBTData(NBTTagCompound aNBT) { + public void loadNBTData(NBTTagCompound aNBT) {additionalConnection = aNBT.getBoolean("additionalConnection"); allowAuto = aNBT.getBoolean("allowAuto"); getProxy().readFromNBT(aNBT); super.loadNBTData(aNBT); @@ -1370,4 +1387,15 @@ public boolean showStackSize(ItemStack is) { } }; } + @Override + public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ) { + additionalConnection = !additionalConnection; + updateValidGridProxySides(); + aPlayer.addChatComponentMessage( + new ChatComponentTranslation("GT5U.hatch.additionalConnection." + additionalConnection)); + return true; + } + + } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java b/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java index 7fb5751..1d30336 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java @@ -181,7 +181,8 @@ public void adjust() { } public void fromAE(@Nonnull IAEFluidStack possible, int intmaxs) { - + if(possible==null){arr + .clear();return;} long all=possible.getStackSize(); all=Math.min(all, intmaxs*1L*Integer.MAX_VALUE); diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java b/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java index ac41471..51fcc20 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java @@ -57,6 +57,7 @@ import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.me.GridAccessException; +import appeng.util.IterationCounter; import appeng.util.item.AEFluidStack; import appeng.util.item.AEItemStack; import gregtech.api.GregTechAPI; @@ -989,7 +990,7 @@ private boolean isAllMEOutputEmpty() { if (itemCache.isEmpty() == false) { return false; } - itemCache = o.getProxy().getStorage().getItemInventory().getStorageList(); + itemCache = o.getProxy().getStorage().getItemInventory().getAvailableItems(AEApi.instance().storage().createItemList(), IterationCounter.fetchNewId()); if (itemCache.isEmpty() == false) { return false; } @@ -1010,7 +1011,7 @@ private boolean isAllMEOutputEmpty() { if (itemCache.isEmpty() == false) { return false; } - itemCache = o.getProxy().getStorage().getFluidInventory().getStorageList(); + itemCache = o.getProxy().getStorage().getFluidInventory().getAvailableItems(AEApi.instance().storage().createFluidList(), IterationCounter.fetchNewId()); if (itemCache.isEmpty() == false) { return false; } @@ -1066,7 +1067,7 @@ private TransferCheckResult checkMEBus(MTEHatchOutputBusME bus, ItemStack check, } } IMEMonitor itemInventory = bus.getProxy().getStorage().getItemInventory(); - itr = itemInventory.getStorageList().iterator(); + itr = itemInventory.getAvailableItems(AEApi.instance().storage().createItemList(), IterationCounter.fetchNewId()).iterator(); // if(check!=null) while (itr.hasNext()) { IAEItemStack next = verifyForRealExistance(itr.next(), itemInventory); @@ -1112,7 +1113,7 @@ private TransferCheckResult checkMEHatch(MTEHatchOutputME bus, FluidStack check, } } IMEMonitor itemInventory = bus.getProxy().getStorage().getFluidInventory(); - itr = itemInventory.getStorageList().iterator(); + itr = itemInventory.getAvailableItems(AEApi.instance().storage().createFluidList(), IterationCounter.fetchNewId()).iterator(); // if(check!=null) while (itr.hasNext()) { IAEFluidStack next = verifyForRealExistance(itr.next(), itemInventory); diff --git a/src/main/java/reobf/proghatches/item/ItemBookTutorial.java b/src/main/java/reobf/proghatches/item/ItemBookTutorial.java index 62830ca..75f6983 100644 --- a/src/main/java/reobf/proghatches/item/ItemBookTutorial.java +++ b/src/main/java/reobf/proghatches/item/ItemBookTutorial.java @@ -1,13 +1,20 @@ package reobf.proghatches.item; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemEditableBook; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.StatCollector; import net.minecraft.util.StringUtils; - +import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.graphs.PowerNode; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.implementations.MTECable; public class ItemBookTutorial extends ItemEditableBook { @@ -25,4 +32,6 @@ public String getItemStackDisplayName(ItemStack p_77653_1_) { return super.getItemStackDisplayName(p_77653_1_); } + + } diff --git a/src/main/java/reobf/proghatches/main/CommonProxy.java b/src/main/java/reobf/proghatches/main/CommonProxy.java index a70b463..adb1d14 100644 --- a/src/main/java/reobf/proghatches/main/CommonProxy.java +++ b/src/main/java/reobf/proghatches/main/CommonProxy.java @@ -41,6 +41,7 @@ import reobf.proghatches.ae.TileRequestTunnel; import reobf.proghatches.ae.TileStockingCircuitRequestInterceptor; import reobf.proghatches.ae.TileStorageProxy; +import reobf.proghatches.ae.part2.ItemPartCoW; import reobf.proghatches.ae.part2.ItemPartRequestTunnel; import reobf.proghatches.block.BlockAnchorAlert; import reobf.proghatches.block.BlockIOHub; @@ -236,7 +237,10 @@ public void preInit(FMLPreInitializationEvent event) { MyMod.part_tunnel = new ItemPartRequestTunnel().setUnlocalizedName("proghatches.part.tunnel") .setTextureName("?"), "proghatches.part.tunnel"); - + GameRegistry.registerItem( + MyMod.part_cow = new ItemPartCoW().setUnlocalizedName("proghatches.part.cow") + .setTextureName("?"), + "proghatches.part.cow"); GameRegistry.registerItem( MyMod.euinterface_p2p = new ItemPartEUP2PInterface().setUnlocalizedName("proghatches.euinterface.p2p") .setTextureName("?"), diff --git a/src/main/java/reobf/proghatches/main/MyMod.java b/src/main/java/reobf/proghatches/main/MyMod.java index a791667..78895e4 100644 --- a/src/main/java/reobf/proghatches/main/MyMod.java +++ b/src/main/java/reobf/proghatches/main/MyMod.java @@ -290,7 +290,11 @@ public void init(FMLInitializationEvent event) { .registerNewLayer( "reobf.proghatches.fmp.LayerCraftingMachine", "appeng.api.implementations.tiles.ICraftingMachine"); - + AEApi.instance() + .partHelper() + .registerNewLayer( + "reobf.proghatches.fmp.LayerUpdatable", + "reobf.proghatches.fmp.IUpdatable"); OCApi.put(iohub, TileIOHub.OCApi.class); OCApi.put(oc_api, ItemAPICard.APIEnv.class); OCApi.put(oc_redstone, ItemGTRedstoneCard.RedstoneEnv.class); @@ -785,6 +789,7 @@ public void init(Entity entity, World world) { public static boolean newGTCache; public static Item part_tunnel; public static BlockOrbSwitcher orbswitcher; + public static Item part_cow; @SubscribeEvent(priority = EventPriority.HIGH, receiveCanceled = false) public void pretick(final TickEvent.ServerTickEvent event) { diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinWailaProvider.java b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinWailaProvider.java index 4ba3b6f..b47620d 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinWailaProvider.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinWailaProvider.java @@ -10,6 +10,7 @@ import appeng.integration.modules.waila.PartWailaDataProvider; import appeng.integration.modules.waila.part.IPartWailaDataProvider; +import reobf.proghatches.ae.part2.PartCoW; import reobf.proghatches.ae.part2.PartRequestTunnel; import reobf.proghatches.eucrafting.PartEUP2PInterface; import reobf.proghatches.eucrafting.PartEUSource; @@ -26,7 +27,7 @@ public void constructor(CallbackInfo a) { providers.add(new PartEUP2PInterface.WailaDataProvider()); providers.add(new PartEUSource.WailaDataProvider()); providers.add(new PartRequestTunnel.WailaDataProvider()); - + providers.add(new PartCoW.WailaDataProvider()); } } diff --git a/src/main/java/reobf/proghatches/oc/ItemCPU.java b/src/main/java/reobf/proghatches/oc/ItemCPU.java index d756c59..3d09734 100644 --- a/src/main/java/reobf/proghatches/oc/ItemCPU.java +++ b/src/main/java/reobf/proghatches/oc/ItemCPU.java @@ -2,10 +2,17 @@ import java.util.Optional; +import gregtech.api.graphs.PowerNode; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.implementations.MTECable; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; - +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import li.cil.oc.api.Network; import li.cil.oc.api.driver.item.Slot; import li.cil.oc.api.machine.Architecture; @@ -141,5 +148,39 @@ public boolean worksWith(ItemStack stack, Class host) return stack.getItem() instanceof ItemCPU; } - + @Override + public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World w, int x, int y, int z, + int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { + if(w.isRemote)return false; + TileEntity te = w.getTileEntity(x, y, z); + if(te instanceof IGregTechTileEntity){ + IGregTechTileEntity gte=(IGregTechTileEntity) te; + IMetaTileEntity mte = gte.getMetaTileEntity(); + if(mte instanceof MTECable){ + MTECable c=(MTECable) mte; + final BaseMetaPipeEntity tBase = (BaseMetaPipeEntity) c.getBaseMetaTileEntity(); + if ((tBase.getNode() instanceof PowerNode )) { + PowerNode tNode=(PowerNode) tBase.getNode(); + tNode.mConsumers.forEach(s->{ + + TileEntity tte = s.mTileEntity; + if(tte!=null){ + System.out.println(tte); + System.out.println(tte.xCoord); + System.out.println(tte.yCoord); + System.out.println(tte.zCoord); + } + + + + }); + + + } + } + + } + + return false; + } } diff --git a/src/main/resources/assets/proghatches/lang/en_US.lang b/src/main/resources/assets/proghatches/lang/en_US.lang index c02a75f..1189bec 100644 --- a/src/main/resources/assets/proghatches/lang/en_US.lang +++ b/src/main/resources/assets/proghatches/lang/en_US.lang @@ -780,3 +780,11 @@ proghatch.phantombus.chat.success=Synchronized successfully to %s Phantom Input proghatch.phantombus.chat.link.exceed=Max amount of links exceed: 1023 proghatch.phantombus.chat.link.success=Linked. Total links: %s proghatch.phantombus.chat.link.noop=Already linked. Total links: %s +item.proghatches.part.cow.name=Channel-over-Wire Panel +item.proghatches.part.cow.tooltips.0=Pass ME channels through GT Cable! +item.proghatches.part.cow.tooltips.1=Connect CoW Panel with GT Cable and use Memory Card to link them +item.proghatches.part.cow.tooltips.2=If link is a success, this panel can pass 32 channels! +item.proghatches.part.cow.tooltips.3=Cannot have more than 2 panels with same freq in same GT wire net +item.proghatches.part.cow.tooltips.4=Can be placed on Dense Cable + + diff --git a/src/main/resources/assets/proghatches/lang/zh_CN.lang b/src/main/resources/assets/proghatches/lang/zh_CN.lang index 2ca5929..5c208dd 100644 --- a/src/main/resources/assets/proghatches/lang/zh_CN.lang +++ b/src/main/resources/assets/proghatches/lang/zh_CN.lang @@ -764,7 +764,7 @@ proghatches.amountmaintainer.interval.0=更新间隔(单位tick) hatch.dualinput.stocking.me.name=库存二合一输入仓(ME) hatch.dualinput.stocking.autopull.me.name=进阶库存二合一输入仓(ME) hatch.dualinput.stocking.autopull.program=自动消耗编程器电路设置虚拟电路槽 -proghatch.stockingdual.exceedintmax=拉取数量超过2.1G, 查看tooltips获取真实数量! +proghatch.stockingdual.exceedintmax=拉取数量超过2.1G, 查看tooltips获取真实数量! proghatch.stockingdual.intmax=最大拉取数量 (单位:int.max) proghatch.stockingdual.intmax.tooltips=最多能拉取int.max(2.1G)的几倍 不要设太大,尤其是当存储中有9.2E个物品时(比如无限水元件),否则可能会非常卡甚至损坏你的存档 proghatch.saved.statistic=优化掉的pushPattern调用次数: %s @@ -778,3 +778,9 @@ proghatch.phantombus.chat.success=成功同步数据到%s个虚拟输入总线 proghatch.phantombus.chat.link.exceed=已达到最大标记数量:1023 proghatch.phantombus.chat.link.success=连接成功 总连接数量:%s proghatch.phantombus.chat.link.noop=连接已经建立,无需连接 总连接数量:%s +item.proghatches.part.cow.name=线传频道面板 +item.proghatches.part.cow.tooltips.0=通过GT导线传递ME频道!线传频道(Channel-over-Wire) +item.proghatches.part.cow.tooltips.1=用GT导线连接CoW面板,并用内存卡连接 +item.proghatches.part.cow.tooltips.2=成功连接后,就能传递至多32频道 +item.proghatches.part.cow.tooltips.3=一个GT线网最多连接2个同频率CoW面板 +item.proghatches.part.cow.tooltips.4=可以放置于致密线缆上 diff --git a/src/main/resources/assets/proghatches/textures/blocks/cow.png b/src/main/resources/assets/proghatches/textures/blocks/cow.png new file mode 100644 index 0000000..d5af87e Binary files /dev/null and b/src/main/resources/assets/proghatches/textures/blocks/cow.png differ