diff --git a/gradle.properties b/gradle.properties index efeb86c..6a882e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,8 @@ autoUpdateBuildScript = false DISABLE_BUILDSCRIPT_GRADLE_UPDATE=true minecraftVersion = 1.7.10 forgeVersion = 10.13.4.1614 - +org.gradle.daemon=false +org.gradle.parallel=false # Specify a MCP channel and mappings version for dependency deobfuscation and the deobfParams task. channel = stable mappingsVersion = 12 @@ -71,7 +72,7 @@ mixinsPackage = mixin.mixins # Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! # This parameter is for legacy compatibility only # Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin -coreModClass = +coreModClass = # If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class # that is annotated with @Mod) you want this to be true. When in doubt: leave it on false! containsMixinsAndOrCoreModOnly = false diff --git a/src/main/java/reobf/proghatches/block/BlockIOHub.java b/src/main/java/reobf/proghatches/block/BlockIOHub.java index 8b2de3c..5bfe0d8 100644 --- a/src/main/java/reobf/proghatches/block/BlockIOHub.java +++ b/src/main/java/reobf/proghatches/block/BlockIOHub.java @@ -1,46 +1,25 @@ package reobf.proghatches.block; -import java.util.Optional; -import java.util.Random; - import com.gtnewhorizons.modularui.api.UIInfos; import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import appeng.core.AppEng; import appeng.core.sync.GuiBridge; import appeng.items.tools.quartz.ToolQuartzCuttingKnife; -import appeng.util.Platform; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.modularui.GT_UIInfos; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.BaseMetaTileEntity; -import gregtech.api.metatileentity.CoverableTileEntity; -import gregtech.api.objects.GT_ItemStack; import gregtech.common.blocks.GT_Material_Machines; -import li.cil.oc.api.network.ManagedEnvironment; -import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; public class BlockIOHub extends BlockContainer { - public BlockIOHub() { super(new GT_Material_Machines()); @@ -52,10 +31,11 @@ public BlockIOHub() { @Override public TileEntity createNewTileEntity(World worldIn, int meta) { - + return new TileIOHub(); } - @SideOnly(Side.CLIENT) + @Override + @SideOnly(Side.CLIENT) protected String getTextureName() { return this.textureName = "proghatches:iohub"; diff --git a/src/main/java/reobf/proghatches/eucrafting/BlockEUInterface.java b/src/main/java/reobf/proghatches/eucrafting/BlockEUInterface.java new file mode 100644 index 0000000..10665b4 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/BlockEUInterface.java @@ -0,0 +1,183 @@ +package reobf.proghatches.eucrafting; + +import java.util.EnumSet; +import java.util.List; + +import com.glodblock.github.FluidCraft; +import com.glodblock.github.client.render.RenderBlockFluidInterface; +import com.glodblock.github.common.block.BlockFluidInterface; +import com.glodblock.github.common.block.FCBaseBlock; +import com.glodblock.github.common.tile.TileFluidInterface; +import com.glodblock.github.inventory.InventoryHandler; +import com.glodblock.github.inventory.gui.GuiType; +import com.glodblock.github.util.BlockPos; +import com.glodblock.github.util.NameConst; +import com.gtnewhorizons.modularui.api.UIInfos; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; + +import appeng.api.util.IOrientable; +import appeng.block.AEBaseTileBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BlockRenderInfo; +import appeng.core.features.AEFeature; +import appeng.core.features.ActivityState; +import appeng.core.features.BlockStackSrc; +import appeng.tile.AEBaseTile; +import appeng.tile.misc.TileInterface; +import appeng.util.Platform; +import cpw.mods.fml.common.Optional.Interface; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import com.glodblock.github.client.textures.FCPartsTexture; +import com.glodblock.github.common.block.BlockFluidInterface; +import com.glodblock.github.common.tile.TileFluidInterface; + +public class BlockEUInterface extends AEBaseTileBlock{ + + + + @Override + protected boolean hasCustomRotation() { + return true; + } + + @Override + protected void customRotateBlock(final IOrientable rotatable, final ForgeDirection axis) { + if (rotatable instanceof TileInterface) { + ((TileInterface) rotatable).setSide(axis); + } + } + + @Override + @SideOnly(Side.CLIENT) + protected BaseBlockRender getRenderer() { + return new BaseBlockRender(false, 20){ + + + + + + @Override + public boolean renderInWorld(final BlockEUInterface block, final IBlockAccess world, final int x, final int y, + final int z, final RenderBlocks renderer) { + final TileInterface ti = block.getTileEntity(world, x, y, z); + final BlockRenderInfo info = block.getRendererInstance(); + + if (ti != null && ti.getForward() != ForgeDirection.UNKNOWN) { + final IIcon side = FCPartsTexture.BlockFluidInterfaceAlternate_Arrow.getIcon(); + info.setTemporaryRenderIcons( + FCPartsTexture.BlockInterfaceAlternate.getIcon(), + block.getIcon(0, 0), + side, + side, + side, + side); + } + + final boolean fz = super.renderInWorld(block, world, x, y, z, renderer); + + info.setTemporaryRenderIcon(null); + + return fz; + } + }; + + }; + + + @Override + public boolean onActivated(final World world, final int x, final int y, final int z, final EntityPlayer player, + final int facing, final float hitX, final float hitY, final float hitZ) { + if (player.isSneaking()) { + + + b:{ + if (NetworkUtils.isClient()) break b; + UIInfos.TILE_MODULAR_UI.open(player, world, x, y, z); + }return true; + } + final TileInterface tg = this.getTileEntity(world, x, y, z); + if (tg != null) { + if (Platform.isServer()) { + InventoryHandler.openGui( + player, + world, + new BlockPos(x, y, z), + ForgeDirection.getOrientation(facing), + GuiType.DUAL_INTERFACE); + } + return true; + } + return false; + } + public BlockEUInterface(Material mat, String name) { + super(mat); + this.setBlockName(name); + setFullBlock(true); + setOpaque(true); + setTileEntity(TileFluidInterface_EU.class); + setFeature(EnumSet.of(AEFeature.Core)); + // this.setBlockTextureName(FluidCraft.MODID + ":" + name); + } + + @Override + public void setTileEntity(final Class clazz) { + AEBaseTile.registerTileItem(clazz, new BlockStackSrc(this, 0, ActivityState.Enabled)); + super.setTileEntity(clazz); + } + + public void setOpaque(boolean opaque) { + this.isOpaque = opaque; + } + + public void setFullBlock(boolean full) { + this.isFullSize = full; + } + + @Override + public void setFeature(final EnumSet f) { + super.setFeature(f); + } + + @SideOnly(Side.CLIENT) + public void addInformation(final ItemStack itemStack, final EntityPlayer player, final List toolTip, + final boolean advancedToolTips) {} + + public void addCheckedInformation(ItemStack itemStack, EntityPlayer player, List toolTip, + boolean advancedToolTips) { + this.addInformation(itemStack, player, toolTip, advancedToolTips); + } + + public ItemStack stack(int size) { + return new ItemStack(this, size); + } + + public ItemStack stack() { + return new ItemStack(this, 1); + } + + + +@Override + public void addCollisionBoxesToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, + Entity e) { + // TODO Auto-generated method stub + super.addCollisionBoxesToList(w, x, y, z, bb, out, e); + } + + +} diff --git a/src/main/java/reobf/proghatches/eucrafting/EUUtil.java b/src/main/java/reobf/proghatches/eucrafting/EUUtil.java new file mode 100644 index 0000000..a41278e --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/EUUtil.java @@ -0,0 +1,132 @@ +package reobf.proghatches.eucrafting; + +import java.util.Optional; + +import javax.annotation.Nullable; + +import com.gtnewhorizons.modularui.ModularUI; +import com.gtnewhorizons.modularui.api.screen.IContainerCreator; +import com.gtnewhorizons.modularui.api.screen.IGuiCreator; +import com.gtnewhorizons.modularui.api.screen.IItemWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.builder.UIBuilder; +import com.gtnewhorizons.modularui.common.builder.UIInfo; +import com.gtnewhorizons.modularui.common.internal.InternalUIMapper; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; + +import appeng.api.AEApi; +import appeng.api.implementations.tiles.ISegmentedInventory; +import appeng.api.parts.IPartHost; +import appeng.tile.AEBaseTile; +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.eucrafting.IEUSource.EUSource; +import reobf.proghatches.main.MyMod; +import reobf.proghatches.net.OpenPartGuiMessage; + +public class EUUtil { + public static void register(){ + AEApi.instance().registries().gridCache().registerGridCache(IEUSource.class, EUSource.class); + + + + } +public static boolean check(ISegmentedInventory inv){ + + IInventory sub = inv.getInventoryByName("upgrades"); + + for(int i=0;is==MyMod.euupgrade) + .isPresent() + ){ + return true; + } + + + + } + + + return false; +} + +@Nullable +public static IGuiProvidingPart select(EntityPlayer player ,int x, int y, int z){ + + NBTTagCompound tag = player.getEntityData(); + if(tag.hasKey(key)==false)return null; + int i=tag.getInteger(key); + //tag.removeTag(key); + TileEntity tt= player.getEntityWorld().getTileEntity(x, y, z); + if(tt instanceof IPartHost){ + IPartHost ae=(IPartHost) tt; + + return (IGuiProvidingPart) Optional.ofNullable(ae.getPart(ForgeDirection.getOrientation(i))) + .filter(s->s instanceof IGuiProvidingPart) + .get(); + + + } + return null; +}public static final String key="proghatches.last.part.direction"; + +public static void open(EntityPlayer player, World world, int x, int y, int z,ForgeDirection dir) { + if (NetworkUtils.isClient()==false||player instanceof FakePlayer) {return;} + NBTTagCompound tag = player.getEntityData(); + tag.setInteger(key,dir.ordinal()); + + + + MyMod.net.sendToServer(new OpenPartGuiMessage(x,y,z,dir)); +} + +public static final UIInfo PART_MODULAR_UI = UIBuilder.of().container((player, world, x, y, z) -> { + return Optional.ofNullable(select(player, x, y, z)).map(part->{ + +UIBuildContext buildContext = new UIBuildContext(player); +ModularWindow window = part.createWindow(buildContext); +return new ModularUIContainer( + new ModularUIContext(buildContext, () -> { + player.inventoryContainer.detectAndSendChanges(); + part.markDirty(); + }), + window, + null); + + + + }).orElse(null) + ; + +}).gui((player, world, x, y, z) -> { + return Optional.ofNullable(select(player, x, y, z)).map(part->{ + + UIBuildContext buildContext = new UIBuildContext(player); + ModularWindow window = part.createWindow(buildContext); + return new ModularGui(new ModularUIContainer( + new ModularUIContext(buildContext, () -> player.inventoryContainer.detectAndSendChanges()), + window, + null)); + + + + }).orElse(null) + ; +}).build(); +} diff --git a/src/main/java/reobf/proghatches/eucrafting/IEUSource.java b/src/main/java/reobf/proghatches/eucrafting/IEUSource.java new file mode 100644 index 0000000..de6dd36 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/IEUSource.java @@ -0,0 +1,134 @@ +package reobf.proghatches.eucrafting; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.LinkedListMultimap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; +import com.google.common.collect.SetMultimap; + +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridCache; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridStorage; +import gregtech.api.enums.GT_Values; +import reobf.proghatches.main.MyMod; + +public interface IEUSource extends IGridCache{ + public long inject(ISource s,long amp,long v); + public void voltageChanged(IDrain gridNode); + public interface ISource{ + public long getVoltage(); + public void reset(); + /*public long request(long amp); + public void refund(long amp); + public long providing();*/ + } + public interface IDrain{ + public long getVoltage(); + + public default long inject(long a,long v){ + accept(a); + return doInject(a,v); + }; + + + public long doInject(long a, long v); + public long expectedAmp(); + public void accept(long a); + public void reset(); + + + } + + public static class EUSource implements IEUSource{ + public IGrid myGrid; + public Multimap cache=HashMultimap.create(); + public ArrayList cache2=new ArrayList<>(); + public EUSource(final IGrid g) { + this.myGrid = g; + + } + + + public long inject(ISource s,long amp,long v){ + //long v=s.getVoltage(); //use actual voltage + long[] a=new long[]{amp}; + cache.get(s.getVoltage()).stream().map(d->{ + long val=Math.min(a[0], d.expectedAmp()); + return (a[0]-=d.inject( val,v)); + }) + .filter(l->l==0)//short-cut the first iteration that makes a[0]==0 + .findFirst() + .orElse(0l); + return amp-a[0]; + } + + @Override + public void onUpdateTick() { + + cache.values().forEach(IDrain::reset); + cache2.forEach(ISource::reset); + + + } + + @Override + public void removeNode(IGridNode gridNode, IGridHost machine) { + + IGridHost mach = gridNode.getMachine(); + if(mach instanceof IDrain){ + cache.values().removeIf(s->s==mach); + }else + if(mach instanceof ISource){ + cache2.remove((ISource) mach); + } + } + + @Override + public void addNode(IGridNode gridNode, IGridHost machine) { + IGridHost mach = gridNode.getMachine(); + if(mach instanceof IDrain){ + cache.put(((IDrain)mach).getVoltage(), (IDrain) mach); + }else + if(mach instanceof ISource){ + cache2.add((ISource) mach); + } + + //ISource is not cached + } +public void voltageChanged(IDrain gridNode){ + cache.entries().removeIf(s->s.getValue()==gridNode); + cache.put(gridNode.getVoltage(), gridNode); +} + + + @Override + public void onSplit(IGridStorage destinationStorage) { + // TODO Auto-generated method stub + + } + + @Override + public void onJoin(IGridStorage sourceStorage) { + // TODO Auto-generated method stub + + } + + @Override + public void populateGridStorage(IGridStorage destinationStorage) { + // TODO Auto-generated method stub + + } +} + + + + +} diff --git a/src/main/java/reobf/proghatches/eucrafting/IGuiProvidingPart.java b/src/main/java/reobf/proghatches/eucrafting/IGuiProvidingPart.java new file mode 100644 index 0000000..bf77256 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/IGuiProvidingPart.java @@ -0,0 +1,12 @@ +package reobf.proghatches.eucrafting; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +public interface IGuiProvidingPart { + + ModularWindow createWindow(UIBuildContext buildContext); + + void markDirty(); + +} diff --git a/src/main/java/reobf/proghatches/eucrafting/IInstantCompletable.java b/src/main/java/reobf/proghatches/eucrafting/IInstantCompletable.java new file mode 100644 index 0000000..f2e292c --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/IInstantCompletable.java @@ -0,0 +1,5 @@ +package reobf.proghatches.eucrafting; + +public interface IInstantCompletable { +public void complete(); +} diff --git a/src/main/java/reobf/proghatches/eucrafting/ItemBlockEUInterface.java b/src/main/java/reobf/proghatches/eucrafting/ItemBlockEUInterface.java new file mode 100644 index 0000000..8503f79 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/ItemBlockEUInterface.java @@ -0,0 +1,15 @@ +package reobf.proghatches.eucrafting; + +import com.glodblock.github.common.block.FCBaseBlock; + +import appeng.block.AEBaseItemBlock; +import net.minecraft.block.Block; + +public class ItemBlockEUInterface extends AEBaseItemBlock{ + private final Block blockType; + + public ItemBlockEUInterface(Block id) { + super(id); + blockType = (Block) id; + } +} diff --git a/src/main/java/reobf/proghatches/eucrafting/ItemEUToken.java b/src/main/java/reobf/proghatches/eucrafting/ItemEUToken.java new file mode 100644 index 0000000..6b53912 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/ItemEUToken.java @@ -0,0 +1,41 @@ +package reobf.proghatches.eucrafting; + +import java.util.List; +import java.util.Optional; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import reobf.proghatches.util.ProghatchesUtil; + +public class ItemEUToken extends Item{ + @SuppressWarnings({ "rawtypes", "unchecked" }) + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { + Optional.ofNullable(p_77624_1_.stackTagCompound) + .ifPresent(s->{ + Optional.of(ProghatchesUtil.deser(s, "EUFI")) + .filter(ss->ss.getLeastSignificantBits()!=0&&ss.getMostSignificantBits()!=0) + .ifPresent(ss-> + p_77624_3_.add("Host UUID:"+ss.toString())); + if(p_77624_1_.stackSize==0) + p_77624_3_.add(s.getLong("voltage")+"V");//this is possible on crafting terminal + else + p_77624_3_.add(s.getLong("voltage")+"V, "+p_77624_1_.stackSize+"*1A"); + + + }); + + } + @Override + public String getUnlocalizedName(ItemStack stack) { + if(stack.getItemDamage()==1){ + + return super.getUnlocalizedName(stack)+".1"; + } + return super.getUnlocalizedName(stack); + } +} diff --git a/src/main/java/reobf/proghatches/eucrafting/ItemPartEUSource.java b/src/main/java/reobf/proghatches/eucrafting/ItemPartEUSource.java new file mode 100644 index 0000000..94f4acd --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/ItemPartEUSource.java @@ -0,0 +1,67 @@ +package reobf.proghatches.eucrafting; + +import javax.annotation.Nullable; + +import com.glodblock.github.FluidCraft; +import com.glodblock.github.common.Config; +import com.glodblock.github.common.item.FCBaseItem; +import com.glodblock.github.common.item.ItemFluidExportBus; +import com.glodblock.github.common.parts.PartFluidExportBus; +import com.glodblock.github.common.tabs.FluidCraftingTabs; +import com.glodblock.github.util.NameConst; + +import appeng.api.AEApi; +import appeng.api.parts.IPartItem; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +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.world.World; + +public class ItemPartEUSource extends Item implements IPartItem { + + public ItemPartEUSource() { + this.setMaxStackSize(64); + // this.setUnlocalizedName(NameConst.ITEM_PART_FLUID_EXPORT); + AEApi.instance().partHelper().setItemBusRenderer(this); + } + + @Nullable + @Override + public PartEUSource createPartFromItemStack(ItemStack is) { + return new PartEUSource(is); + } + + @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 _iconRegister) { + PartEUSource.registerIcons(_iconRegister); + + +} + + @Override + @SideOnly(Side.CLIENT) + public int getSpriteNumber() { + return 0; + } + + +} diff --git a/src/main/java/reobf/proghatches/eucrafting/PartEUSource.java b/src/main/java/reobf/proghatches/eucrafting/PartEUSource.java new file mode 100644 index 0000000..fffb251 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/PartEUSource.java @@ -0,0 +1,557 @@ +package reobf.proghatches.eucrafting; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Random; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import com.glodblock.github.client.textures.FCPartsTexture; +import com.glodblock.github.common.parts.base.FCPart; +import com.google.common.collect.ImmutableList; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; + +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.RedstoneMode; +import appeng.api.config.Settings; +import appeng.api.networking.IGridNode; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.networking.crafting.ICraftingProvider; +import appeng.api.networking.crafting.ICraftingProviderHelper; +import appeng.api.networking.events.MENetworkCraftingPatternChange; +import appeng.api.networking.security.MachineSource; +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.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.parts.PartItemStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.client.texture.CableBusTextures; +import appeng.core.settings.TickRates; +import appeng.me.GridAccessException; +import appeng.parts.AEBasePart; +import appeng.parts.PartBasicState; +import appeng.parts.p2p.IPartGT5Power; +import appeng.util.item.AEItemStack; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.tileentity.IEnergyConnected; +import gregtech.common.gui.modularui.widget.CoverCycleButtonWidget; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.eucrafting.IEUSource.ISource; +import reobf.proghatches.gt.metatileentity.ProgrammingCircuitProvider.CircuitProviderPatternDetial; +import reobf.proghatches.item.ItemProgrammingCircuit; +import reobf.proghatches.lang.LangManager; +import reobf.proghatches.main.MyMod; +import reobf.proghatches.util.ProghatchesUtil; + +public class PartEUSource extends AEBasePart implements IGuiProvidingPart, +ICraftingProvider,IGridTickable,IInstantCompletable +,IPartGT5Power +, ISource{ + @Override + public void markDirty() { + this.getTile().markDirty(); + + } + boolean onoff=true; + long voltage; + long amp; + long consumed; + long ampInjectedthisTick; + boolean recycle=true; + public PartEUSource(ItemStack is) { + super(is); + + } @Override + public final void getBoxes(final IPartCollisionHelper bch) { + bch.addBox(2, 2, 14, 14, 14, 16); + bch.addBox(4, 4, 13, 12, 12, 14); + } + + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(final IPartRenderHelper rh, final RenderBlocks renderer) { + rh.setBounds(2, 2, 14, 14, 14, 16); + + final IIcon sideTexture = CableBusTextures.PartMonitorSides.getIcon(); + final IIcon backTexture = CableBusTextures.PartMonitorBack.getIcon(); + + rh.setTexture( + sideTexture, + sideTexture, + backTexture, + FCPartsTexture.PartTerminalBroad.getIcon(), + sideTexture, + sideTexture); + rh.renderInventoryBox(renderer); + + rh.setInvColor(this.getColor().whiteVariant); + rh.renderInventoryFace(this.getFrontBright(), ForgeDirection.SOUTH, renderer); + + rh.setInvColor(this.getColor().mediumVariant); + rh.renderInventoryFace(this.getFrontBright(), ForgeDirection.SOUTH, renderer); + + rh.setInvColor(this.getColor().blackVariant); + rh.renderInventoryFace(this.getFrontColored(), ForgeDirection.SOUTH, renderer); + + rh.setBounds(4, 4, 13, 12, 12, 14); + rh.renderInventoryBox(renderer); + } +@Override +public boolean onPartActivate(EntityPlayer player, Vec3 pos) { + + //System.out.println(this.getTile().getWorldObj().isRemote); + if(player.isSneaking())return false; + TileEntity t=this.getTile(); + //System.out.println(getSide()); + EUUtil.open(player, player.getEntityWorld(),t.xCoord,t.yCoord,t.zCoord, getSide()); + return true; +} + @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())); + + final IIcon sideTexture = CableBusTextures.PartMonitorSides.getIcon(); + final IIcon backTexture = CableBusTextures.PartMonitorBack.getIcon(); + + rh.setTexture( + sideTexture, + sideTexture, + backTexture, + FCPartsTexture.PartTerminalBroad.getIcon(), + sideTexture, + sideTexture); + + rh.setBounds(2, 2, 14, 14, 14, 16); + rh.renderBlock(x, y, z, renderer); + + if (this.getLightLevel() > 0) { + final int l = 13; + Tessellator.instance.setBrightness(l << 20 | l << 4); + } + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = this + .getSpin(); + + Tessellator.instance.setColorOpaque_I(this.getColor().whiteVariant); + rh.renderFace(x, y, z, this.getFrontBright(), ForgeDirection.SOUTH, renderer); + + Tessellator.instance.setColorOpaque_I(this.getColor().mediumVariant); + rh.renderFace(x, y, z, this.getFrontBright(), ForgeDirection.SOUTH, renderer); + + Tessellator.instance.setColorOpaque_I(this.getColor().blackVariant); + rh.renderFace(x, y, z, this.getFrontColored(), ForgeDirection.SOUTH, renderer); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + + final IIcon sideStatusTexture = CableBusTextures.PartMonitorSidesStatus.getIcon(); + + rh.setTexture( + sideStatusTexture, + sideStatusTexture, + backTexture, + this.getItemStack().getIconIndex(), + sideStatusTexture, + sideStatusTexture); + + rh.setBounds(4, 4, 13, 12, 12, 14); + rh.renderBlock(x, y, z, renderer); + + final boolean hasChan =true;/* (this.getClientFlags() & (FCPart.POWERED_FLAG | FCPart.CHANNEL_FLAG)) + == (FCPart.POWERED_FLAG | FCPart.CHANNEL_FLAG);*/ + final boolean hasPower =true;// (this.getClientFlags() & FCPart.POWERED_FLAG) == FCPart.POWERED_FLAG; + + if (hasChan) { + final int l = 14; + Tessellator.instance.setBrightness(l << 20 | l << 4); + Tessellator.instance.setColorOpaque_I(this.getColor().blackVariant); + } else if (hasPower) { + final int l = 9; + Tessellator.instance.setBrightness(l << 20 | l << 4); + Tessellator.instance.setColorOpaque_I(this.getColor().whiteVariant); + } else { + Tessellator.instance.setBrightness(0); + Tessellator.instance.setColorOpaque_I(0x000000); + } + + final IIcon sideStatusLightTexture = CableBusTextures.PartMonitorSidesStatusLights.getIcon(); + + rh.renderFace(x, y, z, sideStatusLightTexture, ForgeDirection.EAST, renderer); + rh.renderFace(x, y, z, sideStatusLightTexture, ForgeDirection.WEST, renderer); + rh.renderFace(x, y, z, sideStatusLightTexture, ForgeDirection.UP, renderer); + rh.renderFace(x, y, z, sideStatusLightTexture, ForgeDirection.DOWN, renderer); + } + + private IIcon getFrontColored() { + + return a; + } + static IIcon a; + private IIcon getFrontBright() { + + return a; + } + + private int getSpin() { + // TODO Auto-generated method stub + return 0; + } + + public static void registerIcons(IIconRegister _iconRegister) { + + a=_iconRegister.registerIcon("sss"); + } + + + public ModularWindow createWindow(UIBuildContext buildContext) { + TileEntity t=getTile(); + MyMod.LOG.debug("Activated:"+getSide() + +","+t.xCoord + +","+t.yCoord + +","+t.zCoord + ); + + + ModularWindow.Builder builder = ModularWindow.builder(176,107); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + + builder.widget( + ((CycleButtonWidget) new CoverCycleButtonWidget().setSynced(false, true)) + .setGetter(() -> recycle ? 1 : 0) + .setSetter(s -> recycle = s == 1) + .setLength(2) + .setTextureGetter(i -> { + if (i == 1) return GT_UITextures.OVERLAY_BUTTON_CHECKMARK; + return GT_UITextures.OVERLAY_BUTTON_CROSS; + }) + + .addTooltip(0, LangManager.translateToLocal("proghatches.part.recycle.false")) + .addTooltip(1, LangManager.translateToLocal("proghatches.part.recycle.true")) + .setPos(8, 80) + + ); + builder.widget( + ((CycleButtonWidget) new CoverCycleButtonWidget().setSynced(false, true)) + .setGetter(() -> onoff ? 1 : 0) + .setSetter(s -> {onoff = s == 1;postEvent();}) + .setLength(2) + .setTextureGetter(i -> { + if (i == 1) return GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_ON; + return GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF; + }) + + .addTooltip(0, LangManager.translateToLocal("proghatches.part.onoff.false")) + .addTooltip(1, LangManager.translateToLocal("proghatches.part.onoff.true")) + .setPos(8+16, 80) + + ); + builder.widget( + TextWidget.dynamicString(() -> consumed+"/"+amp+"A") + .setSynced(true) + .setPos(58,80) + .addTooltips( + + ImmutableList.of( + LangManager.translateToLocal("proghatches.part.hint.0"), + LangManager.translateToLocal("proghatches.part.hint.1") + ) + + ) + ) + + + ; + + + + + BiFunction,Consumer,Widget> gen=(a,b)->{ + + TextFieldWidget o=Optional.of(new TextFieldWidget()) + .filter(s -> { + s.setText((a.get() + "")); + return true; + }) + .get(); + o.setValidator(val -> { + if (val == null) { + val = ""; + } + return val; + }) + .setSynced(true, true) + .setGetter(() -> { return a.get() + ""; }) + .setSetter(s -> { + try { + b.accept( Math.max(Long.valueOf(s),0l)); + } catch (Exception e) { + b.accept( 0l); + } + onChange(); + o.notifyTooltipChange(); + }) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setMaxLength(50) + .setScrollBar() + .setFocusOnGuiOpen(false) + .setTextColor(Color.WHITE.dark(1)) + + .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD.withOffset(-1, -1, 2, 2)) + .setPos(16,16) + .setSize(16*8,16); + + return o; + }; + builder.widget(gen.apply(()->this.voltage,a->{this.voltage=a;}).setPos(16,16).dynamicTooltip(()->{ + String a=GT_Values.VN[0],b; + long v=8; + for(int i=0;iGT_Values.V[i]){ + a=GT_Values.VN[i+1];v=GT_Values.V[i+1]; + } + } + b=Math.floor((100*(float)voltage/v))+"%"; + + + return ImmutableList.of( + StatCollector.translateToLocal("proghatches.part.tooltip.volt.0"), + StatCollector.translateToLocalFormatted("proghatches.part.tooltip.volt.1",a,b) + );} + + )); + builder.widget(gen.apply(()->this.amp,a->this.amp=a).setPos(16,16+16+2).addTooltip(StatCollector.translateToLocal("proghatches.part.tooltip.amp"))); + builder.widget(new TextWidget("V:").setPos(8,16)); + builder.widget(new TextWidget("A:").setPos(8,16+16+2)); + //builder.bindPlayerInventory(buildContext.getPlayer()); + + return builder.build(); + + } + + + @Override + public long injectEnergyUnits( long aVoltage, long aAmperage) { + //if(getVoltage()==0)return 0; + if(consumed<=ampInjectedthisTick)return 0; + try { + long actual=Math.min(consumed-ampInjectedthisTick,aAmperage); + + long consumed=((IEUSource) getProxy().getGrid().getCache(IEUSource.class)) + .inject(this,actual, aVoltage ); + ampInjectedthisTick+=consumed; + return consumed; + } catch (GridAccessException e) { + + + } + + return 0; + } + @Override + public boolean inputEnergy() { + // TODO Auto-generated method stub + return true; + } + @Override + public boolean outputsEnergy() { + // TODO Auto-generated method stub + return false; + }; + + @Override + public long getVoltage() { + + return voltage; + } + + private void returnItems() { + + + + toReturn.removeIf(s -> { + + try { + return Optional.ofNullable( + + this.getProxy().getStorage().getItemInventory().injectItems(AEItemStack.create(s) + + , Actionable.MODULATE, new MachineSource(this)) + + ).map(IAEItemStack::getStackSize).orElse(0L) == 0L + + ; + + } catch (GridAccessException e) { + return false; + } + }); + + } + @Override + public void readFromNBT(NBTTagCompound data) { + voltage=data.getLong("voltage"); + amp=data.getLong("amp"); + consumed=data.getLong("consumed"); + toReturn.clear(); + int[] count = new int[1]; + NBTTagCompound c; + while ((c = (NBTTagCompound) data.getTag("toReturn" + (count[0]++))) != null) { + toReturn.add(ItemStack.loadItemStackFromNBT(c)); + } + super.readFromNBT(data); + } + @Override + public void writeToNBT(NBTTagCompound data) { + data.setLong("voltage",voltage); + data.setLong("amp",amp); + data.setLong("consumed",consumed); + int[] count = new int[1]; + toReturn.forEach(s -> data.setTag("toReturn" + (count[0]++), s.writeToNBT(new NBTTagCompound()))); + + super.writeToNBT(data); + } + + public void onChange(){ + + postEvent(); + + } + private boolean postEvent() { + try { + this.getProxy() + .getGrid() + .postEvent(new MENetworkCraftingPatternChange(this, getGridNode(ForgeDirection.UNKNOWN))); + return true; + } catch (GridAccessException ignored) { + return false; + } + } + + + @Override + public TickingRequest getTickingRequest(final IGridNode node) { + return new TickingRequest(1,10, false, false); + } + + + + @Override + public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) { + returnItems(); + if(recycle) + try { + IAEItemStack ret = getProxy().getStorage().getItemInventory().extractItems( + AEItemStack.create(buildToken(consumed>Integer.MAX_VALUE?Integer.MAX_VALUE:(int) consumed)) + + , Actionable.MODULATE,new MachineSource(this)); + + if(ret!=null){ + + this.consumed-=ret.getStackSize(); + return TickRateModulation.FASTER; + } + + + + } catch (GridAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return TickRateModulation.SLOWER; + } + + ArrayList toReturn=new ArrayList<>(); + @Override + public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) { + if(consumed>=amp){return false;} + consumed++; + + returnItems(); + toReturn.add(patternDetails.getOutput( + table,this.getTile().getWorldObj() + )); + + return true; + + } + @Override + public boolean isBusy() { + + return (consumed>=amp); + } + + public ItemStack buildToken(int size){ + return Optional.of(new ItemStack(MyMod.eu_token, size, 0)).map(s -> { + s.stackTagCompound = new NBTTagCompound(); + + s.stackTagCompound.setLong("voltage", voltage); + + + return s; + }).get(); + + } + @Override + public void provideCrafting(ICraftingProviderHelper craftingTracker) { + if(onoff==false)return; + ItemStack is=buildToken(1); + craftingTracker + .addCraftingOption(this, new CircuitProviderPatternDetial( + is + )); + + + } + @Override + public void complete() { + returnItems(); + + } + @Override + public void reset() { + ampInjectedthisTick=0; + + } + + + +} diff --git a/src/main/java/reobf/proghatches/eucrafting/TileFluidInterface_EU.java b/src/main/java/reobf/proghatches/eucrafting/TileFluidInterface_EU.java new file mode 100644 index 0000000..f077ec0 --- /dev/null +++ b/src/main/java/reobf/proghatches/eucrafting/TileFluidInterface_EU.java @@ -0,0 +1,942 @@ +package reobf.proghatches.eucrafting; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; + +import javax.annotation.Nullable; + +import com.glodblock.github.common.tile.TileFluidInterface; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; + +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.networking.crafting.ICraftingProviderHelper; +import appeng.api.networking.events.MENetworkCraftingPatternChange; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.MachineSource; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.data.IAEItemStack; +import appeng.me.GridAccessException; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.util.item.AEItemStack; +import cofh.api.energy.IEnergyReceiver; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.tileentity.IEnergyConnected; +import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.widget.CoverCycleButtonWidget; +import ic2.api.energy.tile.IEnergySink; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaDataProvider; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.eucrafting.IEUSource.IDrain; +import reobf.proghatches.gt.metatileentity.ProgrammingCircuitProvider.CircuitProviderPatternDetial; +import reobf.proghatches.lang.LangManager; +import reobf.proghatches.main.MyMod; +import reobf.proghatches.util.ProghatchesUtil; +import thaumcraft.common.lib.WarpEvents; +// TileFluidInterface_EU.class.getName().contains("TileFluidInterface")->true +public class TileFluidInterface_EU extends TileFluidInterface implements ITileWithModularUI,IInstantCompletable, IEnergyConnected,IDrain { + static public IWailaDataProvider provider=new IWailaDataProvider(){ + + @Override + public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) { + + return null; + } + + @Override + public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + + return currenttip; + } + + @Override + public List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + + currenttip.add( + ProghatchesUtil.deser(accessor.getNBTData(), "EUFI").toString() + );return currenttip; + } + + @Override + public List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + + return currenttip; + } + + @Override + public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, + int y, int z) { + ProghatchesUtil.ser(tag, ((TileFluidInterface_EU)te).id, "EUFI"); + return tag; + }}; + public TileFluidInterface_EU() { + super(); + id = UUID.randomUUID(); + initTokenTemplate(); + } + + private UUID id; + final static UUID zero = new UUID(0, 0); + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void read(NBTTagCompound data) { + id = ProghatchesUtil.deser(data, "EUFI"); + if (id.equals(zero)) { + id = UUID.randomUUID(); + } + ; + amp=data.getLong("amp"); + voltage=data.getLong("voltage"); + accepted=data.getLong("accepted"); + averageamp=data.getDouble("averageamp"); + redstoneticks=data.getInteger("redstoneticks"); + expectedamp=data.getLong("expectedamp"); + is.clear(); + IntStream.range(0, data.getInteger("pending_size")).forEach(s->{ + + is.add(ItemStack.loadItemStackFromNBT((NBTTagCompound) data.getTag("pending_"+s))); + + }); + + initTokenTemplate(); + + } +private void initTokenTemplate(){ + token=Optional.of(new ItemStack(MyMod.eu_token, 1, 1)).map(s -> { + s.stackTagCompound = new NBTTagCompound(); + ProghatchesUtil.ser(s.stackTagCompound, id, "EUFI"); + s.stackTagCompound.setLong("voltage", voltage); + + + return s; +}).get(); + + blank_token=Optional.of(new ItemStack(MyMod.eu_token, 1, 0)).map(s -> { + s.stackTagCompound = new NBTTagCompound(); + //ProghatchesUtil.ser(s.stackTagCompound, id, "EUFI"); + s.stackTagCompound.setLong("voltage", voltage); + + + return s; + }).get(); + +} private boolean postEvent() { + try { + this.getProxy() + .getGrid() + .postEvent(new MENetworkCraftingPatternChange(this, getGridNode(ForgeDirection.UNKNOWN))); + return true; + } catch (GridAccessException ignored) { + return false; + } +} + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void write(NBTTagCompound data) { + ProghatchesUtil.ser(data, id, "EUFI"); + data.setLong("amp", amp); + data.setLong("voltage", voltage); + data.setLong("accepted", accepted); + data.setInteger("pending_size", is.size()); + data.setDouble("averageamp", averageamp); + data.setInteger("redstoneticks",redstoneticks); + data.setLong("expectedamp",expectedamp); + for(int i=0;i is = new ArrayList<>(); + + @TileEvent(TileEventType.TICK) + + public void tick() { + if (this.worldObj.isRemote) { + return; + } + returnItems(); + if(this.getWorldObj().isBlockIndirectlyGettingPowered(xCoord,yCoord,zCoord)){ + + this.redstoneticks++; + + } + + if(redstoneticks>0){ + try { + IMEMonitor inv = getProxy().getStorage().getItemInventory(); + IAEItemStack ret =inv.extractItems( + AEItemStack.create(token).setStackSize(amp) + + , Actionable.SIMULATE,new MachineSource(this)); + + if(ret!=null){ + + if(ret.getStackSize()==amp) + {redstoneticks=0; + inv.extractItems( + AEItemStack.create(token).setStackSize(amp) + ,Actionable.MODULATE,new MachineSource(this)); + + inv.injectItems( + AEItemStack.create(blank_token).setStackSize(amp) + ,Actionable.MODULATE,new MachineSource(this)); + amp=0; + } + + } + + + + } catch (GridAccessException e) {} + + } + + } +int redstoneticks; + @Override + public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) { + + returnItems(); + if (patternDetails instanceof PatternDetail) { + is.add(((PatternDetail) patternDetails).out); + // do not call returnItems() here, or items returned will not be considered + // as output + return true; + } + if (patternDetails instanceof WrappedPatternDetail) { + + WrappedPatternDetail p=(WrappedPatternDetail) patternDetails; + int[] count=new int[1]; + int size=table.getSizeInventory(); + for(int i=0;i0){ + count[0]+=is.stackSize; + is.stackSize=0; + table.setInventorySlotContents(i, is); + + break; + }; + } + amp=Math.max(amp, count[0]); + boolean succ=super.pushPattern(p.original, table); + if(succ)is.add(p.extraOut0); + + return succ; + } + return super.pushPattern(patternDetails, table); + + } + + private void returnItems() { + is.removeIf(s -> { + + try { + return Optional.ofNullable( + + this.getProxy().getStorage().getItemInventory().injectItems(AEItemStack.create(s) + + , Actionable.MODULATE, new MachineSource(this)) + + ).map(IAEItemStack::getStackSize).orElse(0L) == 0L + + ; + + } catch (GridAccessException e) { + return false; + } + }); + + } + public static ICraftingPatternDetails wrap(ICraftingPatternDetails d,ItemStack extraIn,ItemStack extraOut){ + if(d.isCraftable())return d; + return new WrappedPatternDetail(d, extraIn, extraOut); + } + + public static class WrappedPatternDetail implements ICraftingPatternDetails { + @Override + public boolean equals(Object obj) { + if(obj ==null){return false;} + if(!(obj instanceof WrappedPatternDetail)){return false;} + return + extraIn.equals(((WrappedPatternDetail)obj).extraIn)&& + extraOut.equals(((WrappedPatternDetail)obj).extraOut)&& + original.equals(((WrappedPatternDetail)obj).original) + ; + } + @Override + public int hashCode() { + + return original.hashCode()^extraIn.hashCode()^extraOut.hashCode(); + } + + + ICraftingPatternDetails original; + final IAEItemStack extraIn; + final IAEItemStack extraOut; + final ItemStack extraIn0; + final ItemStack extraOut0; + public WrappedPatternDetail(ICraftingPatternDetails i,ItemStack extraIn, + ItemStack extraOut){ + if(i.isCraftable()){ throw new IllegalArgumentException("workbench crafting");} + original=i; + this.extraIn=AEItemStack.create(extraIn);extraIn0=extraIn; + this.extraOut=AEItemStack.create(extraOut);extraOut0=extraOut; + } + @Override + public ItemStack getPattern() { + + return Optional.of(new ItemStack(MyMod.fakepattern)).map(s -> { + s.stackTagCompound = new NBTTagCompound(); + s.stackTagCompound.setByte("type", (byte) 2); + s.stackTagCompound.setTag("i", extraIn0.writeToNBT(new NBTTagCompound())); + s.stackTagCompound.setTag("o", extraOut0.writeToNBT(new NBTTagCompound())); + s.stackTagCompound.setTag("p", original.getPattern().writeToNBT(new NBTTagCompound())); + + + return s; + }).get(); + } + + @Override + public boolean isValidItemForSlot(int slotIndex, ItemStack itemStack, World world) { + + throw new IllegalStateException("Impossible"); + } + + @Override + public boolean isCraftable() { + + return false; + } + + @Override + public IAEItemStack[] getInputs() { + + return concat(original.getInputs(),extraIn); + } + private static IAEItemStack[] concat(IAEItemStack[]a,IAEItemStack b){ + IAEItemStack[] c=new IAEItemStack[a.length+1]; + System.arraycopy(a, 0, c, 0, a.length); + c[c.length-1]=b; + return c; + } + @Override + public IAEItemStack[] getCondensedInputs() { + + return concat(original.getCondensedInputs(),extraIn); + } + + @Override + public IAEItemStack[] getCondensedOutputs() { + + return concat(original.getCondensedOutputs(),extraOut); + } + + @Override + public IAEItemStack[] getOutputs() { + + return concat(original.getOutputs(),extraOut); + } + + @Override + public boolean canSubstitute() { + + return original.canSubstitute(); + } + + @Override + public ItemStack getOutput(InventoryCrafting craftingInv, World world) { + + return original.getOutput(craftingInv, world); + } + + @Override + public int getPriority() { + + return original.getPriority(); + } + + @Override + public void setPriority(int priority) { + original.setPriority(priority); + + }} + public static class PatternDetail implements ICraftingPatternDetails { + + public PatternDetail(ItemStack in, ItemStack out) { + this.in = in; + this.out = out; + i = new IAEItemStack[] { AEApi.instance().storage().createItemStack(in) }; + o = new IAEItemStack[] { AEApi.instance().storage().createItemStack(out) }; + + } +@Override +public boolean equals(Object obj) { + if(obj ==null){return false;} + if(!(obj instanceof PatternDetail)){return false;} + PatternDetail p=(PatternDetail) obj; + return i[0].equals(p.i[0])&&o[0].equals(p.o[0]); +} + +@Override +public int hashCode() { + return i[0].hashCode()^o[0].hashCode(); +} + + final ItemStack in; + final ItemStack out; + IAEItemStack[] i, o; + + @Override + public ItemStack getPattern() { + + return Optional.of(new ItemStack(MyMod.fakepattern)).map(s -> { + s.stackTagCompound = new NBTTagCompound(); + s.stackTagCompound.setByte("type", (byte) 1); + s.stackTagCompound.setTag("i", in.writeToNBT(new NBTTagCompound())); + s.stackTagCompound.setTag("o", out.writeToNBT(new NBTTagCompound())); + return s; + }).get(); + } + + @Override + public boolean isValidItemForSlot(int slotIndex, ItemStack itemStack, World world) { + throw new IllegalStateException("workbench crafting"); + } + + @Override + public boolean isCraftable() { + + return false; + } + + @Override + public IAEItemStack[] getInputs() { + + return i; + } + + @Override + public IAEItemStack[] getCondensedInputs() { + + return i; + } + + @Override + public IAEItemStack[] getCondensedOutputs() { + + return o; + } + + @Override + public IAEItemStack[] getOutputs() { + + return o; + } + + @Override + public boolean canSubstitute() { + + return true; + } + + @Override + public ItemStack getOutput(InventoryCrafting craftingInv, World world) { + + return out; + } + + @Override + public int getPriority() { + // TODO Auto-generated method stub + return Integer.MAX_VALUE; + } + + @Override + public void setPriority(int priority) { + // TODO Auto-generated method stub + + } + } + private ItemStack token; + private ItemStack blank_token; + @Override + public boolean isBusy() { + // TODO Auto-generated method stub + return super.isBusy(); + } + + + @Override + public void provideCrafting(ICraftingProviderHelper craftingTracker) { + ICraftingProviderHelper collector=new ICraftingProviderHelper(){ + + @Override + public void addCraftingOption(ICraftingMedium medium, ICraftingPatternDetails api) { + ItemStack a=token.copy(); + + ItemStack b=token.copy(); + + if(expectedamp>0) + { + a.stackSize=b.stackSize=(int) expectedamp; + craftingTracker.addCraftingOption(TileFluidInterface_EU.this,wrap(api, + a, + b + )); + } + else{ + craftingTracker.addCraftingOption(medium, api); + } + } + + @Override + public void setEmitable(IAEItemStack what) {craftingTracker.setEmitable(what);}}; + super.provideCrafting(collector); + craftingTracker.addCraftingOption(this, new PatternDetail(blank_token.copy(), + token.copy() + )); + + } + + @Override + public ForgeDirection getForward() { + // TODO Auto-generated method stub + return super.getForward(); + } + + @Override + public String getCustomName() { + if (super.getCustomName() == null) { + return "EU Interface"; + } + return super.getCustomName(); + } + + @Override + public boolean hasCustomName() { + return true; + } + + @Override + public void setCustomName(String name) { + setName(name); + if (super.getCustomName() == null) { + setName("EU Interface"); + } + } + @Override + public int rows() { + // TODO Auto-generated method stub + return 0; + } + @Override + public int rowSize() { + // TODO Auto-generated method stub + return 0; + } + @Override + public IInventory getPatterns() { + // TODO Auto-generated method stub + return null; + } + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + @Override + public boolean shouldDisplay() { + // TODO Auto-generated method stub + return false; + } + @Override + public void complete() { + returnItems(); + + } + @Override + public byte getColorization() { + // TODO Auto-generated method stub + return 0; + } + @Override + public byte setColorization(byte aColor) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long injectEnergyUnits(ForgeDirection side, long aVoltage, long aAmperage) { + + return 0; + } + @Override + public boolean inputEnergyFrom(ForgeDirection side) { + + return false; + } + @Override + public boolean outputsEnergyTo(ForgeDirection side) { + + return true; + } + long minv,maxv; + boolean updatev; + + long voltage; + long amp; + long expectedamp; + double averageamp; + long instantamp; + @Override + public long getVoltage() { + + return voltage; + }long injectedamp; + @Override + public long doInject(long a, long v) { + if(updatev){ + minv=maxv=v; + updatev=false; + } + else + { + minv=Math.min(minv,v); + maxv=Math.max(maxv,v); + } + long olda=a; + for(ForgeDirection dir:ForgeDirection.VALID_DIRECTIONS){ + long consume=doOutput(v,a,dir); + a-=consume; + injectedamp+=consume; + if(a==0)break; + } + + //doOutput() + + + return olda-a; + } + @Override + public long expectedAmp() { + + return amp-accepted; + } + @Override + public void accept(long a) { + + accepted+=a; + } + long accepted; + @Override + public void reset() { + instantamp=injectedamp; + averageamp=(injectedamp)*0.01+averageamp*0.99; + injectedamp=0; + accepted=0; + } + @Override + public ModularWindow createWindow(UIBuildContext buildContext) { + updatev=true; + ModularWindow.Builder builder = ModularWindow.builder(176,107); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + + /* builder.widget( + ((CycleButtonWidget) new CoverCycleButtonWidget().setSynced(false, true)) + .setGetter(() -> recycle ? 1 : 0) + .setSetter(s -> recycle = s == 1) + .setLength(2) + .setTextureGetter(i -> { + if (i == 1) return GT_UITextures.OVERLAY_BUTTON_CHECKMARK; + return GT_UITextures.OVERLAY_BUTTON_CROSS; + }) + + .addTooltip(0, LangManager.translateToLocal("proghatches.part.recycle.false")) + .addTooltip(1, LangManager.translateToLocal("proghatches.part.recycle.true")) + .setPos(8, 80) + + ); + builder.widget( + ((CycleButtonWidget) new CoverCycleButtonWidget().setSynced(false, true)) + .setGetter(() -> onoff ? 1 : 0) + .setSetter(s -> {onoff = s == 1;postEvent();}) + .setLength(2) + .setTextureGetter(i -> { + if (i == 1) return GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_ON; + return GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF; + }) + + .addTooltip(0, LangManager.translateToLocal("proghatches.part.onoff.false")) + .addTooltip(1, LangManager.translateToLocal("proghatches.part.onoff.true")) + .setPos(8+16, 80) + + );*/ + builder.widget( + TextWidget.dynamicString(() ->instantamp+"/"+String.format("%.2f",averageamp)+"/"+ amp+"A") + .setSynced(true) + .setPos(58,80) + .addTooltips( + + ImmutableList.of( + LangManager.translateToLocal("proghatches.eu.interface.hint.amp"), + LangManager.translateToLocal("proghatches.eu.interface.hint") + + ) + ) + ); + builder.widget( + TextWidget.dynamicString(() ->String.format("[%d~%d]V",minv,maxv)) + .setSynced(true) + .setPos(58,90) + .addTooltips( + + ImmutableList.of( + LangManager.translateToLocal("proghatches.eu.interface.hint.volt") + // , LangManager.translateToLocal("proghatches.eu.interface.hint") + + ) + ) + ); + + + + + + + + BiFunction,Consumer,Widget> gen=(a,b)->{ + + TextFieldWidget o=Optional.of(new TextFieldWidget()) + .filter(s -> { + s.setText((a.get() + "")); + return true; + }) + .get(); + o.setValidator(val -> { + if (val == null) { + val = ""; + } + return val; + }) + .setSynced(true, true) + .setGetter(() -> { return a.get() + ""; }) + .setSetter(s -> { + try { + b.accept( Math.max(Long.valueOf(s),0l)); + } catch (Exception e) { + b.accept( 0l); + } + onChange(); + o.notifyTooltipChange(); + }) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setMaxLength(50) + .setScrollBar() + .setFocusOnGuiOpen(false) + .setTextColor(Color.WHITE.dark(1)) + + .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD.withOffset(-1, -1, 2, 2)) + .setPos(16,16) + .setSize(16*8,16); + + return o; + }; + builder.widget(gen.apply(()->this.voltage,a->{this.voltage=a;}).setPos(16,16).dynamicTooltip(()->{ + String a=GT_Values.VN[0],b; + long v=8; + for(int i=0;iGT_Values.V[i]){ + a=GT_Values.VN[i+1];v=GT_Values.V[i+1]; + } + } + b=Math.floor((100*(float)voltage/v))+"%"; + + + return ImmutableList.of( + StatCollector.translateToLocal("proghatches.eu.interface.tooltip.volt.0"), + StatCollector.translateToLocalFormatted("proghatches.eu.interface.tooltip.volt.1",a,b) + );} + + )); + builder.widget(gen.apply(()->this.expectedamp,a->this.expectedamp=Math.min(a,Integer.MAX_VALUE/*stacksize limit*/)).setPos(16,16+16+2).addTooltip(StatCollector.translateToLocal("proghatches.eu.interface.tooltip.amp"))); + builder.widget(new TextWidget("V:").setPos(8,16)); + builder.widget(new TextWidget("A:").setPos(8,16+16+2)); + //builder.bindPlayerInventory(buildContext.getPlayer()); + + return builder.build(); + + } +public void onChange(){ + IEUSource e; + try { + e = this.getProxy().getGrid().getCache(IEUSource.class); + e.removeNode(this.getProxy().getNode(),this); + e.addNode(this.getProxy().getNode(),this); + + } catch (GridAccessException e1) { + } + + initTokenTemplate(); + postEvent(); +};/* +TileEntity cachedTarget; +boolean isCachedTargetValid; +@Nullable +private TileEntity getTarget() { + TileEntity te; + if (this.isCachedTargetValid) { + te = this.cachedTarget; + if (te == null || !te.isInvalid()) { + return te; + } + } + + this.isCachedTargetValid = true; + te = this.getTile(); + ForgeDirection side = this.getSide(); + return this.cachedTarget = te.getWorldObj() + .getTileEntity(te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ); +}*/ +TileEntity getTarget(ForgeDirection side){ + TileEntity te = this.getTile(); + return te.getWorldObj() + .getTileEntity(te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ); + + + +} +private long injectEnergy(IEnergyConnected te, ForgeDirection oppositeSide, long aVoltage, long aAmperage) { + + return te.injectEnergyUnits(oppositeSide, aVoltage, aAmperage); + +} +/*modified from PartP2PGT5Power*/ +private long doOutput(long aVoltage, long aAmperage,ForgeDirection side) { + + { + TileEntity te = this.getTarget(side); + if (te == null) { + return 0L; + } else { + ForgeDirection oppositeSide = side.getOpposite(); + if (te instanceof IEnergyConnected) { + return injectEnergy((IEnergyConnected) te, oppositeSide, aVoltage, aAmperage); + } else { + if (te instanceof IEnergySink) { + if (((IEnergySink) te).acceptsEnergyFrom(this.getTile(), oppositeSide)) { + long rUsedAmperes = 0L; + while (aAmperage > rUsedAmperes && ((IEnergySink) te).getDemandedEnergy() > 0.0D + && ((IEnergySink) te) + .injectEnergy(oppositeSide, (double) aVoltage, (double) aVoltage) + < (double) aVoltage) + ++rUsedAmperes; + + return rUsedAmperes; + } + } else if (GregTech_API.mOutputRF && te instanceof IEnergyReceiver) { + int rfOut = (int) (aVoltage * (long) GregTech_API.mEUtoRF / 100L); + if (((IEnergyReceiver) te).receiveEnergy(oppositeSide, rfOut, true) == rfOut) { + ((IEnergyReceiver) te).receiveEnergy(oppositeSide, rfOut, false); + return 1L; + } + + if (GregTech_API.mRFExplosions && GregTech_API.sMachineExplosions + && ((IEnergyReceiver) te).getMaxEnergyStored(oppositeSide) < rfOut * 600 + && rfOut > 32 * GregTech_API.mEUtoRF / 100) { + float tStrength = (long) rfOut < GT_Values.V[0] ? 1.0F + : ((long) rfOut < GT_Values.V[1] ? 2.0F + : ((long) rfOut < GT_Values.V[2] ? 3.0F + : ((long) rfOut < GT_Values.V[3] ? 4.0F + : ((long) rfOut < GT_Values.V[4] ? 5.0F + : ((long) rfOut < GT_Values.V[4] * 2L ? 6.0F + : ((long) rfOut < GT_Values.V[5] ? 7.0F + : ((long) rfOut < GT_Values.V[6] + ? 8.0F + : ((long) rfOut + < GT_Values.V[7] + ? 9.0F + : 10.0F)))))))); + int tX = te.xCoord; + int tY = te.yCoord; + int tZ = te.zCoord; + World tWorld = te.getWorldObj(); + GT_Utility.sendSoundToPlayers( + tWorld, + GregTech_API.sSoundList.get(209), + 1.0F, + -1.0F, + tX, + tY, + tZ); + tWorld.setBlock(tX, tY, tZ, Blocks.air); + if (GregTech_API.sMachineExplosions) { + tWorld.createExplosion( + null, + (double) tX + 0.5D, + (double) tY + 0.5D, + (double) tZ + 0.5D, + tStrength, + true); + } + } + } + + return 0L; + } + } + } +} + + + +} diff --git a/src/main/java/reobf/proghatches/gt/cover/RecipeCheckResultCover.java b/src/main/java/reobf/proghatches/gt/cover/RecipeCheckResultCover.java new file mode 100644 index 0000000..3af2a77 --- /dev/null +++ b/src/main/java/reobf/proghatches/gt/cover/RecipeCheckResultCover.java @@ -0,0 +1,52 @@ +package reobf.proghatches.gt.cover; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.util.GT_CoverBehavior; +import net.minecraftforge.common.util.ForgeDirection; + +public class RecipeCheckResultCover extends GT_CoverBehavior{ + @Override + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + + return 1; + } + + + public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity, long aTimer) { + + + aTileEntity.setOutputRedstoneSignal(side, (byte) ((aTimer%2==0)?15:0)); + + + b: if(aTileEntity instanceof IGregTechTileEntity ){ + + IGregTechTileEntity te=(IGregTechTileEntity) aTileEntity; + IMetaTileEntity mte = te.getMetaTileEntity(); + if(mte==null)break b; + if(mte instanceof GT_MetaTileEntity_MultiBlockBase){ + GT_MetaTileEntity_MultiBlockBase mb=(GT_MetaTileEntity_MultiBlockBase) mte; + + + } + + + + + + } + + + + return aCoverVariable; + + + } @Override + public boolean manipulatesSidedRedstoneOutput(ForgeDirection side, int aCoverID, int aCoverVariable, + ICoverable aTileEntity) { + return true; + } +} diff --git a/src/main/java/reobf/proghatches/gt/cover/SmartArmCover.java b/src/main/java/reobf/proghatches/gt/cover/SmartArmCover.java index f16ab60..97b0b7a 100644 --- a/src/main/java/reobf/proghatches/gt/cover/SmartArmCover.java +++ b/src/main/java/reobf/proghatches/gt/cover/SmartArmCover.java @@ -492,7 +492,7 @@ protected void addUIWidgets(ModularWindow.Builder builder) { * widget ->{ * widget * .setLength(2) .setTextureGetter( i->{ - * if(i==1) return GT_UITextures.OVERLAY_BUTTON_EXPORT; + * if(i==1) return GT_UITextures.OVERLAY__EXPORT; * return GT_UITextures.OVERLAY_BUTTON_IMPORT; * } * ).addTooltip(0, LangManager.translateToLocal("programmable_hatches.cover.smart.io.false")) diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java index 00dff1e..9f938a3 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java @@ -418,14 +418,15 @@ private boolean postMEPatternChange() { } return true; } - + long lastSync; @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { super.onPostTick(aBaseMetaTileEntity, aTimer); if (getBaseMetaTileEntity().isServerSide()) { - if (needPatternSync && aTimer % 10 == 0) { + if (needPatternSync && aTimer>lastSync+100) { needPatternSync = !postMEPatternChange(); + lastSync=aTimer; } if (aTimer % 20 == 0) { getBaseMetaTileEntity().setActive(isActive()); diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java b/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java index af1e3b6..30fb0d4 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java @@ -10,6 +10,9 @@ import java.util.Objects; import java.util.Optional; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.InventoryCrafting; @@ -60,6 +63,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.render.TextureFactory; import gregtech.api.util.extensions.ArrayExt; +import reobf.proghatches.eucrafting.TileFluidInterface_EU; import reobf.proghatches.item.ItemProgrammingCircuit; import reobf.proghatches.main.MyMod; import reobf.proghatches.main.registration.Registration; @@ -336,7 +340,7 @@ public void provideCrafting(ICraftingProviderHelper craftingTracker) { */ doSnapshot(); - if (this.mInventory[0] != null) { + /* if (this.mInventory[0] != null)*/ { craftingTracker .addCraftingOption(this, new CircuitProviderPatternDetial(ItemProgrammingCircuit.wrap(mInventory[0]))); @@ -345,44 +349,40 @@ public void provideCrafting(ICraftingProviderHelper craftingTracker) { } - /** - * for ae2 crafting visualizer - */ - public static class FakePattern extends Item implements ICraftingPatternItem { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { - p_77624_3_.add("Technical item, not for use."); - super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); - } - - @Override - public ICraftingPatternDetails getPatternForItem(ItemStack is, World w) { - try { - ItemStack iss = ItemStack.loadItemStackFromNBT(is.getTagCompound()); - return new CircuitProviderPatternDetial(iss); - } catch (Exception ew) { - ew.printStackTrace(); - return new CircuitProviderPatternDetial(new ItemStack(Items.baked_potato)); - } - } - - } public static class CircuitProviderPatternDetial implements ICraftingPatternDetails { - +@Nonnull private ItemStack out; - + @Override + public boolean equals(Object obj) { + if(obj ==null){return false;} + if(!(obj instanceof CircuitProviderPatternDetial)){return false;} + return ItemStack.areItemStacksEqual(out,((CircuitProviderPatternDetial)obj).out); + } + @Override + public int hashCode() { + if(out==null)return 0; + return out.stackTagCompound.hashCode()^ + Integer.valueOf(Item.getIdFromItem(out.getItem())).hashCode()^ + Integer.valueOf(out.getItemDamage()); + } + + public CircuitProviderPatternDetial(ItemStack o) { this.out = o; + /*if(out ==null){ + Thread.dumpStack(); + + System.exit(0);}*/ } @Override public ItemStack getPattern() { return Optional.of(new ItemStack(MyMod.fakepattern)) .map(s -> { - s.stackTagCompound = out.writeToNBT(new NBTTagCompound()); + + s.stackTagCompound = out.writeToNBT(new NBTTagCompound()); + return s; }) .get(); @@ -392,7 +392,7 @@ public ItemStack getPattern() { @Override public boolean isValidItemForSlot(int slotIndex, ItemStack itemStack, World world) { // glad I don't have to implement this - throw new IllegalStateException("Only crafting recipes supported."); + throw new IllegalStateException("workbench crafting"); } @Override diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/RecipeCheckResultDetector.java b/src/main/java/reobf/proghatches/gt/metatileentity/RecipeCheckResultDetector.java new file mode 100644 index 0000000..d0ae61f --- /dev/null +++ b/src/main/java/reobf/proghatches/gt/metatileentity/RecipeCheckResultDetector.java @@ -0,0 +1,132 @@ +package reobf.proghatches.gt.metatileentity; + +import java.lang.reflect.Field; +import java.util.Arrays; + +import com.google.common.collect.ImmutableMap; + +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.BaseMetaTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import reobf.proghatches.main.registration.Registration; + +public class RecipeCheckResultDetector extends GT_MetaTileEntity_Hatch_InputBus +implements IRecipeProcessingAwareHatch +{ + + public RecipeCheckResultDetector(int id, String name, String nameRegional, int tier + ) { + super(id, name, nameRegional, tier, 1, + + reobf.proghatches.main.Config.get("RCRD", ImmutableMap.of())); + Registration.items.add(new ItemStack(GregTech_API.sBlockMachines, 1, id)); + + } public RecipeCheckResultDetector(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription, aTextures); + } + @Override + public void updateSlots() { + + //no-op + } + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + + return new RecipeCheckResultDetector(mName, mTier, mDescriptionArray, mTextures); + } + @Override + public void startRecipeProcessing() {} + /**0 no_recipe + * 1 running fine + * 2 other fail + * */ + private int lastSuccess; + private int check(CheckRecipeResult crr){ + if(crr.wasSuccessful())return 1; + if(crr==CheckRecipeResultRegistry.NO_RECIPE)return 0; + return 2; + } + private static Field f; + private int pulses; + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + + super.loadNBTData(aNBT); + lastSuccess=aNBT.getInteger("lastSuccess"); + pulses=aNBT.getInteger("pulses"); + + } + @Override + public void saveNBTData(NBTTagCompound aNBT) { + + super.saveNBTData(aNBT); + aNBT.setInteger("lastSuccess", lastSuccess); + aNBT.setInteger("pulses", pulses); + } + + static { + f= Arrays.stream(GT_MetaTileEntity_MultiBlockBase.class.getDeclaredFields()) + .filter(s->s.getType()==CheckRecipeResult.class) + .findAny() + .get(); + f.setAccessible(true); + + } + public void start(int lastSuccess,int newSuccess){ + + if(lastSuccess==1&&newSuccess==0){ + pulses++; + } + } + @Override + public boolean allowGeneralRedstoneOutput() { + + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + super.onPostTick(aBaseMetaTileEntity, aTimer); + if(pulses>0){ + pulses--; + BaseMetaTileEntity j; + + aBaseMetaTileEntity.setInternalOutputRedstoneSignal(aBaseMetaTileEntity.getFrontFacing(), (byte) 15); + + }else{ + + aBaseMetaTileEntity.setInternalOutputRedstoneSignal(aBaseMetaTileEntity.getFrontFacing(), (byte) 0); + + + + } + } + + @Override + public CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase controller) { + try { + CheckRecipeResult res=(CheckRecipeResult) f.get(controller); + int newSuccess=check(res); + start(lastSuccess,newSuccess); + lastSuccess=newSuccess; + } catch (Exception e) { + + e.printStackTrace(); + + } + + return CheckRecipeResultRegistry.SUCCESSFUL; + } + +} diff --git a/src/main/java/reobf/proghatches/item/ItemEUUpgradeModule.java b/src/main/java/reobf/proghatches/item/ItemEUUpgradeModule.java new file mode 100644 index 0000000..11c0aca --- /dev/null +++ b/src/main/java/reobf/proghatches/item/ItemEUUpgradeModule.java @@ -0,0 +1,15 @@ +package reobf.proghatches.item; + +import appeng.api.config.Upgrades; +import appeng.api.implementations.items.IUpgradeModule; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class ItemEUUpgradeModule extends Item implements IUpgradeModule{ + + @Override + public Upgrades getType(ItemStack itemstack) { + return Upgrades.REDSTONE;//Upgrades.class is enum + } + +} diff --git a/src/main/java/reobf/proghatches/item/ItemFakePattern.java b/src/main/java/reobf/proghatches/item/ItemFakePattern.java new file mode 100644 index 0000000..88262dd --- /dev/null +++ b/src/main/java/reobf/proghatches/item/ItemFakePattern.java @@ -0,0 +1,64 @@ +package reobf.proghatches.item; + +import java.util.List; + +import appeng.api.implementations.ICraftingPatternItem; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.items.misc.ItemEncodedPattern; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import reobf.proghatches.eucrafting.TileFluidInterface_EU; +import reobf.proghatches.gt.metatileentity.ProgrammingCircuitProvider.CircuitProviderPatternDetial; + +/** + * for ae2 crafting visualizer + */ +public class ItemFakePattern extends Item implements ICraftingPatternItem { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { + p_77624_3_.add("Technical item, not for use."); + super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); + } + + @Override + public ICraftingPatternDetails getPatternForItem(ItemStack is, World w) { + try { + + if(is.getTagCompound().getByte("type")==1){ + ItemStack i = ItemStack.loadItemStackFromNBT((NBTTagCompound) is.getTagCompound().getTag("i")); + ItemStack o = ItemStack.loadItemStackFromNBT((NBTTagCompound) is.getTagCompound().getTag("o")); + return new TileFluidInterface_EU.PatternDetail(i,o); + } + + if(is.getTagCompound().getByte("type")==2){ + ItemStack i = ItemStack.loadItemStackFromNBT((NBTTagCompound) is.getTagCompound().getTag("i")); + ItemStack o = ItemStack.loadItemStackFromNBT((NBTTagCompound) is.getTagCompound().getTag("o")); + ItemStack p = ItemStack.loadItemStackFromNBT((NBTTagCompound) is.getTagCompound().getTag("p")); + + return new TileFluidInterface_EU.WrappedPatternDetail( + ((ItemEncodedPattern)p.getItem()).getPatternForItem(p, w) + ,i,o); + } + + + + + + ItemStack iss = ItemStack.loadItemStackFromNBT(is.getTagCompound()); + return new CircuitProviderPatternDetial(iss); + + + + } catch (Exception ew) { + ew.printStackTrace(); + return new CircuitProviderPatternDetial(new ItemStack(Items.baked_potato)); + } + } + +} \ No newline at end of file diff --git a/src/main/java/reobf/proghatches/main/CommonProxy.java b/src/main/java/reobf/proghatches/main/CommonProxy.java index 959323b..47634b3 100644 --- a/src/main/java/reobf/proghatches/main/CommonProxy.java +++ b/src/main/java/reobf/proghatches/main/CommonProxy.java @@ -1,10 +1,16 @@ package reobf.proghatches.main; +import net.minecraft.block.material.Material; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import java.util.ArrayList; import java.util.List; +import com.glodblock.github.common.item.FCBaseItemBlock; +import com.glodblock.github.common.tabs.FluidCraftingTabs; +import com.glodblock.github.common.tile.TileFluidAutoFiller; +import com.glodblock.github.util.NameConst; import com.google.common.base.Optional; import appeng.api.AEApi; @@ -21,8 +27,16 @@ import reobf.proghatches.block.ItemBlockIOHub; import reobf.proghatches.block.TileIOHub; +import reobf.proghatches.eucrafting.BlockEUInterface; +import reobf.proghatches.eucrafting.EUUtil; +import reobf.proghatches.eucrafting.ItemBlockEUInterface; +import reobf.proghatches.eucrafting.ItemEUToken; +import reobf.proghatches.eucrafting.ItemPartEUSource; +import reobf.proghatches.eucrafting.TileFluidInterface_EU; import reobf.proghatches.gt.metatileentity.ProgrammingCircuitProvider; import reobf.proghatches.item.ItemDedicatedCover; +import reobf.proghatches.item.ItemEUUpgradeModule; +import reobf.proghatches.item.ItemFakePattern; import reobf.proghatches.item.ItemProgrammingCircuit; import reobf.proghatches.item.ItemProgrammingToolkit; import reobf.proghatches.item.ItemSmartArm; @@ -49,14 +63,24 @@ public void preInit(FMLPreInitializationEvent event) { GameRegistry.registerTileEntity(TileIOHub.class, "proghatches.iohub"); GameRegistry.registerTileEntity(TileWirelessPeripheralStation.class, "proghatches.peripheral_station"); GameRegistry.registerTileEntity(TileCoprocessor.class, "proghatches.coprocessor"); + + GameRegistry.registerTileEntity(TileFluidInterface_EU.class, "proghatches.euinterface"); + + + // setCreativeTab(FluidCraftingTabs.INSTANCE); + GameRegistry.registerItem( + MyMod.euupgrade = new ItemEUUpgradeModule().setUnlocalizedName("proghatches.eu_upgrade_module") + .setTextureName("?"), + "proghatches.eu_upgrade_module"); + GameRegistry.registerItem( MyMod.progcircuit = new ItemProgrammingCircuit().setUnlocalizedName("prog_circuit") .setTextureName("?"), "prog_circuit"); GameRegistry.registerItem( - MyMod.fakepattern = new ProgrammingCircuitProvider.FakePattern().setUnlocalizedName("fake_pattern") + MyMod.fakepattern = new ItemFakePattern().setUnlocalizedName("fake_pattern") .setTextureName("?"), "fake_pattern"); GameRegistry.registerItem( @@ -86,6 +110,15 @@ public void preInit(FMLPreInitializationEvent event) { .setUnlocalizedName("proghatches.oc.peripheral_card") .setTextureName("proghatches:peripheral_card"), "proghatches.oc.peripheral_card"); + GameRegistry.registerItem( + MyMod.eu_token = new ItemEUToken().setUnlocalizedName("eu_token") + .setTextureName("?"), + "eu_token"); + + + + + MyMod.iohub =GameRegistry.registerBlock( new BlockIOHub(),ItemBlockIOHub.class,"proghatches.iohub"); MyMod.pstation =GameRegistry.registerBlock( @@ -103,25 +136,34 @@ public void preInit(FMLPreInitializationEvent event) { public static ProgHatchCreativeTab tab; - // load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed) public void init(FMLInitializationEvent event) { tab = new ProgHatchCreativeTab("proghatches"); //AEApi.instance().registries().gridCache().registerGridCache(null, null);; // AEApi.instance().registries().interfaceTerminal().register(TileFluidInterface.class); new Registration().run(); + EUUtil.register(); } - // postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed) - public void postInit(FMLPostInitializationEvent event) { - + public void postInit(FMLPostInitializationEvent event) { + //cannot be done in preinit + GameRegistry.registerBlock( + MyMod.block_euinterface = + new BlockEUInterface(Material.iron,"proghatches.euinterface"), ItemBlockEUInterface.class, "proghatches.euinterface"); + GameRegistry.registerItem( + MyMod.eu_source_part = new ItemPartEUSource().setUnlocalizedName("proghatches.part.eu.source") + .setTextureName("?"), + "proghatches.part.eu.source"); new PHRecipes().run(); } public static void callbackRegister(IWailaRegistrar registrar) { registrar.registerBodyProvider(TileWirelessPeripheralStation.provider, MyMod.pstation.getClass()); registrar.registerNBTProvider(TileWirelessPeripheralStation.provider, MyMod.pstation.getClass()); + registrar.registerBodyProvider(TileFluidInterface_EU.provider,BlockEUInterface.class); + registrar.registerNBTProvider(TileFluidInterface_EU.provider,BlockEUInterface.class); + } // register server commands in this event handler (Remove if not needed) public void serverStarting(FMLServerStartingEvent event) {} diff --git a/src/main/java/reobf/proghatches/main/MyMod.java b/src/main/java/reobf/proghatches/main/MyMod.java index ffa7585..920b2c2 100644 --- a/src/main/java/reobf/proghatches/main/MyMod.java +++ b/src/main/java/reobf/proghatches/main/MyMod.java @@ -16,7 +16,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - +import appeng.me.cluster.implementations.CraftingCPUCluster; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; @@ -26,9 +26,13 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.relauncher.Side; import reobf.proghatches.Tags; import reobf.proghatches.block.TileIOHub.OCApi; +import reobf.proghatches.eucrafting.BlockEUInterface; import reobf.proghatches.lang.LangManager; +import reobf.proghatches.net.OpenPartGuiMessage; import reobf.proghatches.oc.WirelessPeripheralManager; import reobf.proghatches.util.ProghatchesUtil; @@ -39,11 +43,11 @@ */ ) public class MyMod { - + public static SimpleNetworkWrapper net=new SimpleNetworkWrapper(Tags.MODID); public static Item progcircuit; public static Item toolkit; public static final Logger LOG = LogManager.getLogger(Tags.MODID); - + static {CraftingCPUCluster.class.getDeclaredFields();} @SidedProxy(clientSide = "reobf.proghatches.main.ClientProxy", serverSide = "reobf.proghatches.main.CommonProxy") public static CommonProxy proxy; public static Item fakepattern; @@ -54,12 +58,16 @@ public class MyMod { public static Block iohub; public static Block pstation; public static Item pitem; - + public static Item euupgrade; + + public static Item eu_token; + public static Item eu_source_part; + public static BlockEUInterface block_euinterface; @Mod.EventHandler // preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the // GameRegistry." (Remove if not needed) public void preInit(FMLPreInitializationEvent event) { - event.getSuggestedConfigurationFile(); + net.registerMessage(new OpenPartGuiMessage.Handler(), OpenPartGuiMessage.class, 0, Side.SERVER); proxy.preInit(event); } diff --git a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java index b389b98..5388c90 100644 --- a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java +++ b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java @@ -26,6 +26,7 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import appeng.me.cluster.implementations.CraftingCPUCluster; import cpw.mods.fml.relauncher.FMLLaunchHandler; import reobf.proghatches.Tags; import ru.timeconqueror.spongemixins.MinecraftURLClassPath; @@ -65,7 +66,7 @@ public void acceptTargets(Set myTargets, Set otherTargets) { @SuppressWarnings("unused") @Override public List getMixins() { - + File f=new File( System.getProperty("user.dir")+File.separator+"config","proghatches.mixin.properties"); if(f.exists()==false){ try { @@ -93,7 +94,7 @@ public List getMixins() { }finally{} System.out.println(pp); - System.out.println("ccccccccccccccccccccccccccc"); + // System.out.println("ccccccccccccccccccccccccccc"); System.out.println("following warnings like 'Error loading class: xxxx' is normal and safe to ignore"); @@ -103,12 +104,18 @@ public List getMixins() { ArrayList ret = new ArrayList<>(); + + + ret.add("eucrafting."+"MixinInterface"); + ret.add("eucrafting."+"MixinInterfacePart"); + ret.add("eucrafting."+"MixinUpgrade"); + ret.add("eucrafting."+"MixinInstantComplete"); + ret.add("MixinAwarenessForDualHatch"); if(!"true".equals(pp.get("noRemoveUnusedCacheInModularUIContainer"))) ret.add("MixinRemoveUnunsedItemStackCache"); - //ret.add("MixinInterface"); - // ret.add("MixinInterfacePart"); + if(!"true".equals(pp.get("noRecipeFilterForDualHatch"))){ ret.add("MixinGTRecipeFilter"); // GT Multiblock will not set recipe filter of DualInputHatch, set it via mixin diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterfacePart.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterfacePart.java deleted file mode 100644 index cb64eb0..0000000 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterfacePart.java +++ /dev/null @@ -1,29 +0,0 @@ -package reobf.proghatches.main.mixin.mixins; - -import org.spongepowered.asm.mixin.Mixin; - -import appeng.parts.misc.PartInterface; -import appeng.parts.p2p.IPartGT5Power; -import appeng.tile.misc.TileInterface; -@Mixin(value = PartInterface.class, remap = false, priority = 1) -public class MixinInterfacePart implements IPartGT5Power{ - - @Override - public long injectEnergyUnits(long voltage, long amperage) { - - return 0; - } - - @Override - public boolean inputEnergy() { - - return true; - } - - @Override - public boolean outputsEnergy() { - - return true; - } - -} diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInstantComplete.java b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInstantComplete.java new file mode 100644 index 0000000..1c22578 --- /dev/null +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInstantComplete.java @@ -0,0 +1,53 @@ +package reobf.proghatches.main.mixin.mixins.eucrafting; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.util.DimensionalCoord; +import appeng.me.cache.CraftingGridCache; +import appeng.me.cluster.implementations.CraftingCPUCluster; +import appeng.util.item.AEItemStack; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import reobf.proghatches.eucrafting.IInstantCompletable; + +@Mixin(value = CraftingCPUCluster.class, remap = false, priority = 1) +public class MixinInstantComplete { + + + @Inject(at = { @At(value = "INVOKE",shift=Shift.BEFORE, + target = "markDirty()V") }, + method="executeCrafting" + + ,require=1,locals=LocalCapture.CAPTURE_FAILHARD + + ) + + + public void a(IEnergyGrid eg, CraftingGridCache cc, CallbackInfo ci, Iterator i, Map.Entry e, ICraftingPatternDetails details, InventoryCrafting ic, boolean pushedPattern, Iterator var8, ICraftingMedium m + ) { + + if(m instanceof IInstantCompletable){ + ((IInstantCompletable)m) + .complete(); + + } + + + + } + +} diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterface.java b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInterface.java similarity index 72% rename from src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterface.java rename to src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInterface.java index 3ac49b7..350aef9 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterface.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInterface.java @@ -1,15 +1,18 @@ -package reobf.proghatches.main.mixin.mixins; +package reobf.proghatches.main.mixin.mixins.eucrafting; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Mixin; +import appeng.api.implementations.tiles.ISegmentedInventory; import appeng.me.cluster.implementations.CraftingCPUCluster; +import appeng.tile.grid.AENetworkInvTile; import appeng.tile.misc.TileInterface; import gregtech.api.interfaces.tileentity.IEnergyConnected; import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.eucrafting.EUUtil; @Mixin(value = TileInterface.class, remap = false, priority = 1) -public class MixinInterface implements IEnergyConnected { +public abstract class MixinInterface implements IEnergyConnected, ISegmentedInventory { @Override public byte getColorization() { @@ -31,14 +34,14 @@ public long injectEnergyUnits(ForgeDirection side, long aVoltage, long aAmperage @Override public boolean inputEnergyFrom(ForgeDirection side) { - // TODO Auto-generated method stub - return true; + + return false; } @Override public boolean outputsEnergyTo(ForgeDirection side) { - // TODO Auto-generated method stub - return true; + + return EUUtil.check(this); } } diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInterfacePart.java b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInterfacePart.java new file mode 100644 index 0000000..5048577 --- /dev/null +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinInterfacePart.java @@ -0,0 +1,38 @@ +package reobf.proghatches.main.mixin.mixins.eucrafting; + +import org.spongepowered.asm.mixin.Mixin; + +import appeng.api.implementations.tiles.ISegmentedInventory; +import appeng.api.parts.IPart; +import appeng.parts.PartBasicState; +import appeng.parts.misc.PartInterface; +import appeng.parts.p2p.IPartGT5Power; +import appeng.tile.misc.TileInterface; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.eucrafting.EUUtil; +import reobf.proghatches.eucrafting.IEUSource; +@Mixin(value = PartInterface.class, remap = false, priority = 1) +public abstract class MixinInterfacePart implements IPartGT5Power, ISegmentedInventory,IPart{ + + + + @Override + public long injectEnergyUnits(long voltage, long amperage) { + + return 0; + } + + @Override + public boolean inputEnergy() { + + return false; + } + + @Override + public boolean outputsEnergy() { + //System.out.println(getGridNode().getGrid().getCache(IEUSource.class).toString()); + return EUUtil.check(this); + } + +} diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinUpgrade.java b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinUpgrade.java new file mode 100644 index 0000000..2b086ab --- /dev/null +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/eucrafting/MixinUpgrade.java @@ -0,0 +1,54 @@ +package reobf.proghatches.main.mixin.mixins.eucrafting; + +import java.util.Optional; + +import org.spongepowered.asm.lib.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import appeng.parts.automation.StackUpgradeInventory; +import appeng.parts.automation.UpgradeInventory; +import appeng.parts.misc.PartInterface; +import appeng.tile.inventory.IAEAppEngInventory; +import net.minecraft.item.ItemStack; +import reobf.proghatches.main.MyMod; + +@Mixin(value = StackUpgradeInventory.class, remap = false, priority = 1) +public abstract class MixinUpgrade extends UpgradeInventory{ + + public MixinUpgrade() { + super(null, 0); + } + + /* @Inject(method = "isItemValidForSlot", + at = @At(value = "HEAD"), cancellable = true + )*/ + public boolean isItemValidForSlot(final int ix, final ItemStack itemstack) { + if(itemstack!=null){ + if(itemstack.getItem()==MyMod.euupgrade){ + + + for(int i=0;is==MyMod.euupgrade) + .isPresent() + ){ + return false; + } + + + + } + + return true; + } + } + return super.isItemValidForSlot(ix, itemstack); + } +} diff --git a/src/main/java/reobf/proghatches/main/registration/ProgHatchCreativeTab.java b/src/main/java/reobf/proghatches/main/registration/ProgHatchCreativeTab.java index d6e2695..94df66e 100644 --- a/src/main/java/reobf/proghatches/main/registration/ProgHatchCreativeTab.java +++ b/src/main/java/reobf/proghatches/main/registration/ProgHatchCreativeTab.java @@ -64,6 +64,7 @@ public void displayAllReleventItems(List p_78018_1_) { p_78018_1_.add(new ItemStack(MyMod.iohub, 1)); p_78018_1_.add(new ItemStack(MyMod.pitem, 1)); p_78018_1_.add(new ItemStack(MyMod.pstation, 1)); + p_78018_1_.add(new ItemStack(MyMod.euupgrade, 1)); } @Override diff --git a/src/main/java/reobf/proghatches/main/registration/Registration.java b/src/main/java/reobf/proghatches/main/registration/Registration.java index 0859a2f..210a5c9 100644 --- a/src/main/java/reobf/proghatches/main/registration/Registration.java +++ b/src/main/java/reobf/proghatches/main/registration/Registration.java @@ -11,6 +11,7 @@ import gregtech.api.enums.GT_Values; import gregtech.api.render.TextureFactory; import reobf.proghatches.gt.cover.ProgrammingCover; +import reobf.proghatches.gt.cover.RecipeCheckResultCover; import reobf.proghatches.gt.cover.RecipeOutputAwarenessCover; import reobf.proghatches.gt.cover.SmartArmCover; import reobf.proghatches.gt.cover.WirelessControlCover; @@ -20,6 +21,7 @@ import reobf.proghatches.gt.metatileentity.FilterOutputBus; import reobf.proghatches.gt.metatileentity.PatternDualInputHatch; import reobf.proghatches.gt.metatileentity.ProgrammingCircuitProvider; +import reobf.proghatches.gt.metatileentity.RecipeCheckResultDetector; import reobf.proghatches.gt.metatileentity.RemoteInputBus; import reobf.proghatches.gt.metatileentity.RemoteInputHatch; import reobf.proghatches.gt.metatileentity.SuperfluidHatch; @@ -41,8 +43,9 @@ public class Registration implements Runnable { public final static int RemoteInputHatchOffset = 67; public final static int SuperFluidHatch = 68; public final static int PatternOffset = 69; - public final static int TenaciousOffset = 70; - public final static int FilterOffset = 74; + public final static int TenaciousOffset = 70;// -73 + public final static int FilterOffset = 74;// -77 + private static final int RecipeCheckResultDetectorOffset = 78; @Override public void run() { @@ -130,6 +133,13 @@ public void run() { MACHINE_CASINGS[1][0], TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCREEN_GLOW)), new RecipeOutputAwarenessCover()); + GregTech_API.registerCover( + new ItemStack(MyMod.cover, 1, 14), + TextureFactory.of( + MACHINE_CASINGS[1][0], + TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCREEN_GLOW)), + + new RecipeCheckResultCover()); for (int i = 0; i < 15; i++) { ; @@ -188,16 +198,22 @@ public void run() { for (int i = 0; i < 4; i++) new FilterOutputBus( Config.metaTileEntityOffset + TenaciousOffset + i, "hatch.output.tenacious." + i, - LangManager.translateToLocal("hatch.output.tenacious.name"), + LangManager.translateToLocalFormatted("hatch.output.tenacious.name", GT_Values.VN[i]), i, true); for (int i = 0; i < 4; i++) new FilterOutputBus( Config.metaTileEntityOffset + FilterOffset + i, "hatch.output.filter." + i, - LangManager.translateToLocal("hatch.output.filter.name"), + LangManager.translateToLocalFormatted("hatch.output.filter.name", GT_Values.VN[i]), i, false); + + new RecipeCheckResultDetector( + Config.metaTileEntityOffset + RecipeCheckResultDetectorOffset, + "recipe_check_result_detector", + LangManager.translateToLocal("recipe_check_result_detector.name"), + 0); } diff --git a/src/main/java/reobf/proghatches/net/OpenPartGuiMessage.java b/src/main/java/reobf/proghatches/net/OpenPartGuiMessage.java new file mode 100644 index 0000000..f7036ab --- /dev/null +++ b/src/main/java/reobf/proghatches/net/OpenPartGuiMessage.java @@ -0,0 +1,54 @@ +package reobf.proghatches.net; + +import appeng.client.gui.widgets.GuiProgressBar.Direction; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import reobf.proghatches.eucrafting.EUUtil; + +public class OpenPartGuiMessage implements IMessage{ + public static class Handler implements IMessageHandler{ + + @Override + public OpenPartGuiMessage onMessage(OpenPartGuiMessage message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + NBTTagCompound tag = player.getEntityData(); + tag.setInteger(EUUtil.key,message.dir.ordinal()); + EUUtil.PART_MODULAR_UI + .open(player, player.worldObj, message.x, message.y, message.z); + return null; + }} + + int x;int y;int z;ForgeDirection dir; + public OpenPartGuiMessage(){} + public OpenPartGuiMessage(int x,int y,int z,ForgeDirection dir){ + this.x=x; + this.y=y; + this.z=z; + this.dir=dir; + + + } + + @Override + public void fromBytes(ByteBuf buf) { + x=buf.readInt(); + y=buf.readInt(); + z=buf.readInt(); + dir=ForgeDirection.getOrientation(buf.readInt()); + + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + buf.writeInt(dir.ordinal()); + } + +} diff --git a/src/main/java/reobf/proghatches/oc/TileWirelessPeripheralStation.java b/src/main/java/reobf/proghatches/oc/TileWirelessPeripheralStation.java index fe5a973..cd7c7d8 100644 --- a/src/main/java/reobf/proghatches/oc/TileWirelessPeripheralStation.java +++ b/src/main/java/reobf/proghatches/oc/TileWirelessPeripheralStation.java @@ -102,13 +102,13 @@ public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { - return ImmutableList.of(); + return currenttip; } @Override public List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { - return ImmutableList.of(); + return currenttip; } }; public static class ItemBlock extends net.minecraft.item.ItemBlock{ diff --git a/src/main/java/reobf/proghatches/util/ProghatchesUtil.java b/src/main/java/reobf/proghatches/util/ProghatchesUtil.java index 2592153..3f6101e 100644 --- a/src/main/java/reobf/proghatches/util/ProghatchesUtil.java +++ b/src/main/java/reobf/proghatches/util/ProghatchesUtil.java @@ -200,4 +200,16 @@ public void detectAndSendChanges(boolean init) { @Override public void readOnClient(int id, PacketBuffer buf) throws IOException {} @Override public void readOnServer(int id, PacketBuffer buf) throws IOException {}}); } + + + + public static UUID deser(NBTTagCompound tag,String name){ + return new UUID(tag.getLong(name+"_UUID_M"), tag.getLong(name+"_UUID_L")); + } + public static void ser(NBTTagCompound tag, UUID id,String name){ + tag.setLong(name+"_UUID_M", id.getMostSignificantBits()); + tag.setLong(name+"_UUID_L", id.getLeastSignificantBits()); + } + + } diff --git a/src/main/resources/assets/proghatches/lang/en_US.lang b/src/main/resources/assets/proghatches/lang/en_US.lang index 41089e7..96208b5 100644 --- a/src/main/resources/assets/proghatches/lang/en_US.lang +++ b/src/main/resources/assets/proghatches/lang/en_US.lang @@ -192,3 +192,24 @@ hatch.input.buffered.superfluid.name=Superfluid Dual Input Hatch hatch.input.buffered.me.name=Programmable Crafting Input Buffer hatch.output.tenacious.name=Tenacious Ouput Bus (%s) hatch.output.filter.name=Filter Ouput Bus (%s) +recipe_check_result_detector.name=Idle Detector +item.proghatches.eu_upgrade_module.name=Current Packet Decoder Card(WIP) +proghatches.part.tooltip.amp=The expected current that the adjacent Dynamo Hatch can provide. +proghatches.part.tooltip.volt.0=The expected voltage that the adjacent Dynamo Hatch can provide. +proghatches.part.tooltip.volt.1=Level:%s %s +proghatches.part.recycle.false=Do not recycle Current Packet +proghatches.part.recycle.true=Recycle Current Packet +proghatches.part.hint.0=Requested Current/Total Current +proghatches.part.hint.1=Note:if requested Current > 0, better not modify the expected A/V listed above. +proghatches.part.onoff.false=Disallow Current Packet request +proghatches.part.onoff.true=Allow Current Packet request +item.proghatches.part.eu.source.name=EU Source +tile.proghatches.euinterface.name=EU Drain Interface +item.eu_token.name=Current packet +item.eu_token.1.name=Current packet(Bound) +proghatches.eu.interface.hint.amp=Instantaneous/Actual(5s average)/Assigned Current +proghatches.eu.interface.hint.volt=Actual Voltage(min/max voltage since GUI open) +proghatches.eu.interface.hint=Note:if expected Current > 0, better not modify the expected A/V listed above. +proghatches.eu.interface.tooltip.volt.0=The expected voltage that the Interface should emit. +proghatches.eu.interface.tooltip.volt.1=Level:%s %s +proghatches.eu.interface.tooltip.amp=The expected current that the Interface should emit. diff --git a/src/main/resources/assets/proghatches/lang/en_US/RCRD.lang b/src/main/resources/assets/proghatches/lang/en_US/RCRD.lang new file mode 100644 index 0000000..678faff --- /dev/null +++ b/src/main/resources/assets/proghatches/lang/en_US/RCRD.lang @@ -0,0 +1,4 @@ +Emits a 1-tick redstone pulse when a running Multiblock turn off due to no recipe found. +Redstone wire cannot pass 1-tick pulse? Try Redstone P2P or Redstone Conduit! +Put in a normal Input Bus position. +Cannot be shared between Multiblocks! \ No newline at end of file diff --git a/src/main/resources/assets/proghatches/lang/zh_CN.lang b/src/main/resources/assets/proghatches/lang/zh_CN.lang index 7bec5b1..3dbb8d8 100644 --- a/src/main/resources/assets/proghatches/lang/zh_CN.lang +++ b/src/main/resources/assets/proghatches/lang/zh_CN.lang @@ -186,7 +186,7 @@ tile.proghatches.peripheral_station.tooltip.2=只能和无线外设桥接卡建 tile.proghatches.peripheral_station.tooltip.3=距离:16格 无法跨维度 tile.proghatches.peripheral_station.tooltip.4=不占用组件数量 tile.proghatches.peripheral_station.tooltip=5 -programmable_hatches.gt.updateEveryTick=此模式用于每tick强制触发仓室的转移,以防(由于bug或某些corner case)转移过程未能正确触发 如果仓室工作正常,应该关闭此功能以优化服务器负载 +programmable_hatches.gt.updateEveryTick=此模式用于每tick强制触发仓室的转移,以防(由于bug或某些corner case)转移过程未能正确触发 如果仓室工作正常,应该关闭此功能以优化服务器负载,此时开启此功能也不会获得更高的游戏内处理效率 programmable_hatches.addedby=Added by §1ProgrammableHatches§r programmable_hatches.gt.lang.dir=zh_CN hatch.input.dual.tier.name=编程二合一输入仓 (%s) @@ -202,3 +202,24 @@ hatch.input.buffered.superfluid.name=超级流体二合一输入仓 hatch.input.buffered.me.name=编程样板输入总成 hatch.output.tenacious.name=吝物输出总线 (%s) hatch.output.filter.name=过滤输出总线 (%s) +recipe_check_result_detector.name=空闲检测器 +item.proghatches.eu_upgrade_module.name=电流封包解码卡(WIP) +proghatches.part.tooltip.amp=前方动力仓能提供的期望电流 +proghatches.part.tooltip.volt.0=前方动力仓能提供的期望电压 +proghatches.part.tooltip.volt.1=电压等级:%s %s +proghatches.part.recycle.false=不自动回收电流封包 +proghatches.part.recycle.true=自动回收电流封包 +proghatches.part.hint.0=占用的安培数/总安培数 +proghatches.part.hint.1=注意:占用的安培数如果不为0时,应当避免更改期望值 +proghatches.part.onoff.false=暂停提供封包 +proghatches.part.onoff.true=提供封包 +item.proghatches.part.eu.source.name=EU源 +tile.proghatches.euinterface.name=EU接口 +item.eu_token.name=电流封包 +item.eu_token.1.name=电流封包(绑定) +proghatches.eu.interface.hint.amp=瞬时/平均(5秒平均)/已分配到电流 +proghatches.eu.interface.hint.volt=实际电压(GUI打开后统计的 最小/最大 值) +proghatches.eu.interface.hint=注意:期望电流如果不为0时,应当避免更改期望值 +proghatches.eu.interface.tooltip.volt.0=EU接口期望电压 +proghatches.eu.interface.tooltip.volt.1=电压等级:%s %s +proghatches.eu.interface.tooltip.amp=EU接口期望电流 diff --git a/src/main/resources/assets/proghatches/lang/zh_CN/RCRD.lang b/src/main/resources/assets/proghatches/lang/zh_CN/RCRD.lang new file mode 100644 index 0000000..1079f26 --- /dev/null +++ b/src/main/resources/assets/proghatches/lang/zh_CN/RCRD.lang @@ -0,0 +1,4 @@ +当多方块机器由于未找到配方从工作状态停机时,发射1tick红石信号 +红石线无法传递1tick脉冲?试试红石P2P或者红石导管吧! +占用一个输入总线位置 +不能被多方块结构共享! \ No newline at end of file