From 80ea67fd7623535b30424b7618d69767b926c330 Mon Sep 17 00:00:00 2001 From: Technus Date: Tue, 30 Jul 2019 17:54:28 +0200 Subject: TEMP WORK --- .../technus/tectech/loader/gui/ModGuiHandler.java | 4 + .../tectech/loader/thing/MachineLoader.java | 36 ++++ .../tectech/mechanics/avr/SidedRedstone.java | 2 +- .../technus/tectech/thing/CustomItemList.java | 2 + .../technus/tectech/thing/item/AvrProgrammer.java | 216 +++++++++++++++++++++ .../item/DebugElementalInstanceContainer_EM.java | 2 +- .../item/ElementalDefinitionContainer_EM.java | 4 +- .../item/ElementalDefinitionScanStorage_EM.java | 2 +- .../technus/tectech/thing/item/EuMeterGT.java | 4 +- .../thing/item/FrontRotationTriggerItem.java | 3 + .../tectech/thing/item/gui/ProgrammerScreen.java | 13 ++ .../single/GT_MetaTileEntity_MicroController.java | 187 ++++++++++++++++++ ...T_MetaTileEntity_MicroControllerTileEntity.java | 169 ---------------- 13 files changed, 470 insertions(+), 174 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java create mode 100644 src/main/java/com/github/technus/tectech/thing/item/gui/ProgrammerScreen.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroController.java delete mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroControllerTileEntity.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java b/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java index 44585d1b91..e555437104 100644 --- a/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java +++ b/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.loader.gui; +import com.github.technus.tectech.thing.item.gui.ProgrammerScreen; import com.github.technus.tectech.thing.item.gui.ScanDisplayScreen; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.entity.player.EntityPlayer; @@ -10,6 +11,7 @@ import net.minecraft.world.World; */ public class ModGuiHandler implements IGuiHandler { public static final int SCAN_DISPLAY_SCREEN_ID =0; + public static final int PROGRAMMER_DISPLAY_SCREEN_ID =1; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { @@ -20,6 +22,8 @@ public class ModGuiHandler implements IGuiHandler { public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == SCAN_DISPLAY_SCREEN_ID) { return new ScanDisplayScreen(player); + }else if(ID==PROGRAMMER_DISPLAY_SCREEN_ID){ + return new ProgrammerScreen(player); } return null; } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java index 988fd30031..f92f78e4c6 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java @@ -90,6 +90,42 @@ public class MachineLoader implements Runnable { eM_muffler_UXV.set(new GT_MetaTileEntity_Hatch_OverflowElemental( 15025, "hatch.emmuffler.tier.13", "UXV Overflow Output Hatch", 13, 125e12f).getStackForm(1L)); + + // =================================================================================================== + // Microcontrollers + // =================================================================================================== + + eM_avr_HV.set(new GT_MetaTileEntity_MicroController( + 15030, "machine.avr.tier.08", "HV AVR Micro-controller", 3).getStackForm(1L)); + + eM_avr_EV.set(new GT_MetaTileEntity_MicroController( + 15031, "machine.avr.tier.08", "EV AVR Micro-controller", 4).getStackForm(1L)); + + eM_avr_IV.set(new GT_MetaTileEntity_MicroController( + 15032, "machine.avr.tier.08", "IV AVR Micro-controller", 5).getStackForm(1L)); + + eM_avr_LuV.set(new GT_MetaTileEntity_MicroController( + 15033, "machine.avr.tier.08", "LuV AVR Micro-controller", 6).getStackForm(1L)); + + eM_avr_ZPM.set(new GT_MetaTileEntity_MicroController( + 15034, "machine.avr.tier.08", "ZPM AVR Micro-controller", 7).getStackForm(1L)); + + eM_avr_UV.set(new GT_MetaTileEntity_MicroController( + 15035, "machine.avr.tier.08", "UV AVR Micro-controller", 8).getStackForm(1L)); + + eM_avr_UHV.set(new GT_MetaTileEntity_MicroController( + 15036, "machine.avr.tier.09", "UHV AVR Micro-controller", 9).getStackForm(1L)); + + eM_avr_UEV.set(new GT_MetaTileEntity_MicroController( + 15037, "machine.avr.tier.10", "UEV AVR Micro-controller", 10).getStackForm(1L)); + + eM_avr_UIV.set(new GT_MetaTileEntity_MicroController( + 15038, "machine.avr.tier.11", "UIV AVR Micro-controller", 11).getStackForm(1L)); + + eM_avr_UMV.set(new GT_MetaTileEntity_MicroController( + 15039, "machine.avr.tier.12", "UMV AVR Micro-controller", 12).getStackForm(1L)); + + // =================================================================================================== // Multi AMP Power INPUTS // =================================================================================================== diff --git a/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java b/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java index 9488b9280f..fd351631f3 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java +++ b/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java @@ -8,7 +8,7 @@ public class SidedRedstone extends RegisterPackageSync { public static final RSINT RSINT =new RSINT(); public SidedRedstone(int offset) { - super(offset, 23); + super(offset, Register.values().length); addRegisters(Register.values()); addBits(RegisterBitsPCMSK.values()); addBits(RegisterBitsPCFR.values()); diff --git a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java index 969283fa15..788edecaab 100644 --- a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java +++ b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java @@ -89,6 +89,8 @@ public enum CustomItemList implements IItemContainer { Machine_Multi_BHG, hint_0,hint_1,hint_2,hint_3,hint_4,hint_5,hint_6,hint_7,hint_8,hint_9,hint_10,hint_11, hint_general,hint_air,hint_noAir,hint_error, + eM_avr_HV, eM_avr_EV, eM_avr_IV, eM_avr_LuV, eM_avr_ZPM, eM_avr_UV, eM_avr_UHV, eM_avr_UEV, eM_avr_UIV, eM_avr_UMV, + scanContainer,parametrizerMemory; diff --git a/src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java b/src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java new file mode 100644 index 0000000000..1d61d0744c --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java @@ -0,0 +1,216 @@ +package com.github.technus.tectech.thing.item; + +import com.github.technus.avrClone.AvrCore; +import com.github.technus.avrClone.instructions.InstructionRegistry; +import com.github.technus.avrClone.memory.program.ProgramMemory; +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.loader.gui.ModGuiHandler; +import com.github.technus.tectech.thing.metaTileEntity.single.GT_MetaTileEntity_MicroController; +import cpw.mods.fml.common.Optional; +import dan200.computercraft.api.filesystem.IMount; +import dan200.computercraft.api.filesystem.IWritableMount; +import dan200.computercraft.api.media.IMedia; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import li.cil.oc.api.fs.FileSystem; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; + +import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; + +@Optional.InterfaceList( + @Optional.Interface(iface="dan200.computercraft.api.media.IMedia",modid = "ComputerCraft"), + @Optional.Interface(iface="li.cil.oc.api.fs.FileSystem",modid="OpenComputers")) +public class AvrProgrammer extends Item implements IMedia,FileSystem { + public static AvrProgrammer INSTANCE=new AvrProgrammer(); + + private AvrProgrammer(){ + setMaxStackSize(1); + setHasSubtypes(true); + setUnlocalizedName("em.programmer"); + setTextureName(MODID + ":itemProgrammer"); + setCreativeTab(creativeTabTecTech); + } + + @Override + public boolean onItemUseFirst(ItemStack stack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int side, float hitX, float hitY, float hitZ) { + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if(tTileEntity==null || aPlayer instanceof FakePlayer) { + return aPlayer instanceof EntityPlayerMP; + } + if (aPlayer instanceof EntityPlayerMP) { + if (tTileEntity instanceof IGregTechTileEntity) { + IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); + if (metaTE instanceof GT_MetaTileEntity_MicroController) { + if (aPlayer.isSneaking()) { + if(stack.stackTagCompound.hasKey("pgm")) { + NBTTagCompound pgm = stack.stackTagCompound.getCompoundTag("pgm"); + if (pgm.hasKey("instructions")) { + AvrCore core = ((GT_MetaTileEntity_MicroController) metaTE).core; + InstructionRegistry registry = InstructionRegistry.REGISTRIES. + get(pgm.getString("instructionRegistry")); + if (registry != null) { + core.setProgramMemory(new ProgramMemory( + registry, + pgm.getBoolean("immersive"), + pgm.getIntArray("instructions"), + pgm.getIntArray("param0"), + pgm.getIntArray("param1"))); + } + } + } + } else { + NBTTagCompound tag=new NBTTagCompound(); + metaTE.saveNBTData(tag); + stack.stackTagCompound.setTag("avr",tag.getCompoundTag("avr")); + } + return true; + } + } + } + return false; + } + + public void writeToProgrammer(ItemStack stack,InstructionRegistry registry, boolean immersive, List strings) throws Exception{ + writeToProgrammer(stack,new ProgramMemory(registry,immersive,strings)); + } + + public void writeToProgrammer(ItemStack stack,InstructionRegistry registry, boolean immersive, String... strings)throws Exception{ + writeToProgrammer(stack,new ProgramMemory(registry,immersive,strings)); + } + + public void writeToProgrammer(ItemStack stack, ProgramMemory programMemory) { + NBTTagCompound pgm=new NBTTagCompound(); + pgm.setIntArray("instructions",programMemory.instructions); + pgm.setIntArray("param0",programMemory.param0); + pgm.setIntArray("param1",programMemory.param1); + pgm.setBoolean("immersive",programMemory.immersiveOperands); + pgm.setString("instructionRegistry",programMemory.registry.toString()); + stack.stackTagCompound.setTag("pgm",pgm); + } + + @Override + public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { + if(world.isRemote){ + player.openGui(TecTech.instance, ModGuiHandler.PROGRAMMER_DISPLAY_SCREEN_ID, world, 0, 0, 0); + } + return itemStack; + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer ep, List aList, boolean boo) { + if(aStack.stackTagCompound.hasKey("avr")) { + NBTTagCompound avr=aStack.stackTagCompound.getCompoundTag("avr"); + aList.add("Current PC: " +avr.getInteger("programCounter")); + aList.add("Awoken: " +avr.getBoolean("awoken")); + aList.add("Active: " +avr.getBoolean("active")); + aList.add("Debug: " +avr.getBoolean("debugRun")); + aList.add("Delay: " +avr.getBoolean("delay")); + } + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public String getLabel(ItemStack itemStack) { + return itemStack.getDisplayName(); + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public boolean setLabel(ItemStack itemStack, String s) { + itemStack.setStackDisplayName(s); + return true; + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public String getAudioTitle(ItemStack itemStack) { + return null; + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public String getAudioRecordName(ItemStack itemStack) { + return null; + } + + @Override + @Optional.Method(modid = "ComputerCraft") + public IMount createDataMount(ItemStack itemStack, World world) { + return new IWritableMount() { + @Override + public void makeDirectory(String s) throws IOException { + throw new IOException("Cannot make dir!"); + } + + @Override + public void delete(String s) throws IOException { + if("avr".equals(s)) { + itemStack.stackTagCompound.removeTag("avr"); + }else { + throw new IOException("Cannot remove file!"); + } + } + + @Override + public OutputStream openForWrite(String s) throws IOException { + return null; + } + + @Override + public OutputStream openForAppend(String s) throws IOException { + return null; + } + + @Override + public long getRemainingSpace() throws IOException { + return 1024000-getSize("avr"); + } + + @Override + public boolean exists(String s) throws IOException { + return "avr".equals(s) && itemStack.getTagCompound().hasKey(s); + } + + @Override + public boolean isDirectory(String s) throws IOException { + return false; + } + + @Override + public void list(String s, List list) throws IOException { + + } + + @Override + public long getSize(String s) throws IOException { + return "avr".equals(s)?1:0; + } + + @Override + public InputStream openForRead(String s) throws IOException { + return null; + } + }; + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + ItemStack stack=new ItemStack(item, 1, 0); + stack.setTagCompound(new NBTTagCompound()); + list.add(stack); + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/item/DebugElementalInstanceContainer_EM.java b/src/main/java/com/github/technus/tectech/thing/item/DebugElementalInstanceContainer_EM.java index 3b09d37a33..61c6e3114a 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/DebugElementalInstanceContainer_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/item/DebugElementalInstanceContainer_EM.java @@ -161,6 +161,6 @@ public final class DebugElementalInstanceContainer_EM extends Item implements IE @Override public FontRenderer getFontRenderer(ItemStack stack) { - return (FontRenderer) (Object) TecTechFontRender.INSTANCE; + return TecTechFontRender.INSTANCE; } } diff --git a/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionContainer_EM.java b/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionContainer_EM.java index 8de3d1540c..b5a9eacf68 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionContainer_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionContainer_EM.java @@ -19,6 +19,7 @@ import java.util.List; import static com.github.technus.tectech.Reference.MODID; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; /** * Created by Tec on 15.03.2017. @@ -30,6 +31,7 @@ public final class ElementalDefinitionContainer_EM extends Item implements IElem setMaxStackSize(1); setUnlocalizedName("em.definitionContainer"); setTextureName(MODID + ":itemDefinitionContainer"); + setCreativeTab(creativeTabTecTech); } //return previous thing @@ -146,6 +148,6 @@ public final class ElementalDefinitionContainer_EM extends Item implements IElem @Override public FontRenderer getFontRenderer(ItemStack stack) { - return (FontRenderer) (Object) TecTechFontRender.INSTANCE; + return TecTechFontRender.INSTANCE; } } diff --git a/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionScanStorage_EM.java b/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionScanStorage_EM.java index 87b76696bb..eb8663e1c2 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionScanStorage_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionScanStorage_EM.java @@ -152,6 +152,6 @@ public final class ElementalDefinitionScanStorage_EM extends Item implements IEl @Override public FontRenderer getFontRenderer(ItemStack stack) { - return (FontRenderer) (Object) TecTechFontRender.INSTANCE; + return TecTechFontRender.INSTANCE; } } diff --git a/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java b/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java index 8edcd32bdb..d95b9845bd 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java +++ b/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java @@ -21,14 +21,16 @@ import java.util.ArrayList; import java.util.List; import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; public class EuMeterGT extends Item { public static EuMeterGT INSTANCE; private EuMeterGT() { + setMaxStackSize(1); setUnlocalizedName("em.EuMeterGT"); setTextureName(MODID + ":itemEuMeterGT"); - setMaxStackSize(1); + setCreativeTab(creativeTabTecTech); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java b/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java index 15567bc477..014c8b6721 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java +++ b/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java @@ -17,6 +17,7 @@ import net.minecraftforge.common.util.FakePlayer; import java.util.List; import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; /** * Created by Tec on 15.03.2017. @@ -25,8 +26,10 @@ public final class FrontRotationTriggerItem extends Item { public static FrontRotationTriggerItem INSTANCE; private FrontRotationTriggerItem() { + setMaxStackSize(1); setUnlocalizedName("em.frontRotate"); setTextureName(MODID + ":itemFrontRotate"); + setCreativeTab(creativeTabTecTech); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/item/gui/ProgrammerScreen.java b/src/main/java/com/github/technus/tectech/thing/item/gui/ProgrammerScreen.java new file mode 100644 index 0000000000..8584f28d45 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/item/gui/ProgrammerScreen.java @@ -0,0 +1,13 @@ +package com.github.technus.tectech.thing.item.gui; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; + +public class ProgrammerScreen extends GuiScreen { + private NBTTagCompound tag; + + public ProgrammerScreen(EntityPlayer player){ + tag=player.getHeldItem().getTagCompound(); + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroController.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroController.java new file mode 100644 index 0000000000..ef5426a272 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroController.java @@ -0,0 +1,187 @@ +package com.github.technus.tectech.thing.metaTileEntity.single; + +import com.github.technus.avrClone.AvrCore; +import com.github.technus.avrClone.instructions.ExecutionEvent; +import com.github.technus.avrClone.instructions.Instruction; +import com.github.technus.avrClone.instructions.InstructionRegistry; +import com.github.technus.avrClone.instructions.exceptions.DebugEvent; +import com.github.technus.avrClone.instructions.exceptions.DelayEvent; +import com.github.technus.avrClone.memory.EepromMemory; +import com.github.technus.avrClone.memory.RemovableMemory; +import com.github.technus.avrClone.memory.program.ProgramMemory; +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; +import com.github.technus.tectech.mechanics.avr.SidedRedstone; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import static com.github.technus.tectech.thing.metaTileEntity.single.GT_MetaTileEntity_DataReader.READER_OFFLINE; +import static com.github.technus.tectech.thing.metaTileEntity.single.GT_MetaTileEntity_DataReader.READER_ONLINE; + +public class GT_MetaTileEntity_MicroController extends GT_MetaTileEntity_TieredMachineBlock { + public static final int OPS_PER_TICK_MAX =512; + + static { + Instruction.random= TecTech.RANDOM; + } + public AvrCore core; + private int[] tempData; + public boolean debugRun; + private int delay; + private int maxLoad; + + public static final SidedRedstone sidedRedstone=new SidedRedstone(0x16); + + public GT_MetaTileEntity_MicroController(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 0, "AVR Micro-controller"); + Util.setTier(aTier,this); + } + + public GT_MetaTileEntity_MicroController(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 0, aDescription, aTextures); + Util.setTier(aTier,this); + core=new AvrCore(); + core.setUsingImmersiveOperands(false); + core.setInstructionRegistry(InstructionRegistry.INSTRUCTION_REGISTRY_OP); + core.setDataMemory(Math.max(64,1< eeprom=core.getEepromMemory(); + if(eeprom!=null){ + avr.setInteger("eepromSize",eeprom.getDefinition().getSize()); + } + if(core.dataMemory!=null){ + avr.setIntArray("dataMemory",core.dataMemory); + } + tag.setTag("avr",avr); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (tempData != null) { + //todo discovery of components + core.dataMemory = tempData; + tempData = null; + } + if (aBaseMetaTileEntity.isActive()) { + sidedRedstone.preSync(core,aBaseMetaTileEntity); + core.interruptsHandle(); + if (core.awoken) { + delay=0; + for (int load=0; load < maxLoad;) { + load+=core.getInstruction().getCost(core); + ExecutionEvent executionEvent = core.cpuCycleForce(); + if (executionEvent != null) { + if (executionEvent.throwable instanceof DelayEvent) { + delay = executionEvent.data[0]; + break; + } else if (executionEvent.throwable instanceof DebugEvent) { + if(debugRun) { + aBaseMetaTileEntity.setActive(false); + break; + } + } + } + } + }else if(delay>0){ + delay--; + if(delay==0){ + core.awoken=true; + } + } + sidedRedstone.postSync(core,aBaseMetaTileEntity); + } + core.active=aBaseMetaTileEntity.isActive(); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { + return true; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { + return true; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if(aBaseMetaTileEntity.getWorld()==null){ + if(aSide==aFacing){ + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], aActive ? READER_ONLINE : READER_OFFLINE}; + } + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]}; + } + if(aSide==aBaseMetaTileEntity.getFrontFacing()){ + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], aActive ? READER_ONLINE : READER_OFFLINE}; + }else if(aSide==aFacing){ + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; + } + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]}; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + return null; + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroControllerTileEntity.java deleted file mode 100644 index 6692c19cea..0000000000 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroControllerTileEntity.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.github.technus.tectech.thing.metaTileEntity.single; - -import com.github.technus.avrClone.AvrCore; -import com.github.technus.avrClone.instructions.ExecutionEvent; -import com.github.technus.avrClone.instructions.Instruction; -import com.github.technus.avrClone.instructions.InstructionRegistry; -import com.github.technus.avrClone.instructions.exceptions.DebugEvent; -import com.github.technus.avrClone.instructions.exceptions.DelayEvent; -import com.github.technus.avrClone.memory.EepromMemory; -import com.github.technus.avrClone.memory.RemovableMemory; -import com.github.technus.avrClone.memory.program.ProgramMemory; -import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.Util; -import com.github.technus.tectech.mechanics.avr.SidedRedstone; -import gregtech.api.enums.Textures; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; -import gregtech.api.objects.GT_RenderedTexture; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import static com.github.technus.tectech.thing.metaTileEntity.single.GT_MetaTileEntity_DataReader.READER_OFFLINE; -import static com.github.technus.tectech.thing.metaTileEntity.single.GT_MetaTileEntity_DataReader.READER_ONLINE; - -public class GT_MetaTileEntity_MicroControllerTileEntity extends GT_MetaTileEntity_TieredMachineBlock { - static { - Instruction.random= TecTech.RANDOM; - } - private AvrCore core; - private int[] tempData; - private boolean debugRun; - private int delay; - - public static final SidedRedstone sidedRedstone=new SidedRedstone(0x1b); - - public GT_MetaTileEntity_MicroControllerTileEntity(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 0, "AVR Micro-controller"); - Util.setTier(aTier,this); - } - - public GT_MetaTileEntity_MicroControllerTileEntity(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 0, aDescription, aTextures); - Util.setTier(aTier,this); - core=new AvrCore(); - core.setUsingImmersiveOperands(false); - core.setInstructionRegistry(InstructionRegistry.INSTRUCTION_REGISTRY_OP); - core.setDataMemory(1< eeprom=core.getEepromMemory(); - if(eeprom!=null){ - tag.setInteger("eepromSize",eeprom.getDefinition().getSize()); - } - if(core.dataMemory!=null){ - tag.setIntArray("dataMemory",core.dataMemory); - } - } - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (tempData != null) { - //todo discovery of components - core.dataMemory = tempData; - tempData = null; - } - if (core.active) { - sidedRedstone.preSync(core,aBaseMetaTileEntity); - core.interruptsHandle(); - if (core.awoken) { - delay=0; - for (int i = 0, cycles = Math.min(1 << mTier, 512); i < cycles; i++) { - ExecutionEvent executionEvent = core.cpuCycleForce(); - if (executionEvent != null) { - if (executionEvent.throwable instanceof DelayEvent) { - delay = executionEvent.data[0]; - break; - } else if (debugRun && executionEvent.throwable instanceof DebugEvent) { - core.active = false; - break; - } - } - } - }else if(delay>0){ - delay--; - if(delay==0){ - core.awoken=true; - } - } - sidedRedstone.postSync(core,aBaseMetaTileEntity); - } - } - - @Override - public boolean allowPullStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { - return true; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { - return true; - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - if(aBaseMetaTileEntity.getWorld()==null){ - if(aSide==aFacing){ - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], aActive ? READER_ONLINE : READER_OFFLINE}; - } - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]}; - } - if(aSide==aBaseMetaTileEntity.getFrontFacing()){ - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], aActive ? READER_ONLINE : READER_OFFLINE}; - }else if(aSide==aFacing){ - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT)}; - } - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]}; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - return null; - } -} -- cgit