From ef951d663fcd41b2e5064acdbb3596146fc6eabe Mon Sep 17 00:00:00 2001 From: Technus Date: Sun, 21 Jul 2019 21:18:05 +0200 Subject: Include avrcore --- .../tileEntity/MicroControllerTileEntity.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java new file mode 100644 index 0000000000..798a2daa47 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java @@ -0,0 +1,26 @@ +package com.github.technus.tectech.thing.tileEntity; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +public class MicroControllerTileEntity extends TileEntity { + @Override + public void readFromNBT(NBTTagCompound p_145839_1_) { + super.readFromNBT(p_145839_1_); + } + + @Override + public void writeToNBT(NBTTagCompound p_145841_1_) { + super.writeToNBT(p_145841_1_); + } + + @Override + public void invalidate() { + super.invalidate(); + } + + @Override + public void updateEntity() { + super.updateEntity(); + } +} -- cgit From 371249f1920a64cae74722adac1e9275d30133d7 Mon Sep 17 00:00:00 2001 From: Technus Date: Tue, 23 Jul 2019 11:19:53 +0200 Subject: Add names and symbols for neutron, proton --- .gitignore | 2 + AVRcore | 2 +- build.gradle | 2 +- .../core/templates/cElementalPrimitive.java | 4 +- .../core/transformations/bTransformationInfo.java | 38 ++++++++--------- .../definitions/complex/dHadronDefinition.java | 49 ++++++++++++++++++---- .../item/DebugElementalInstanceContainer_EM.java | 4 +- .../tileEntity/MicroControllerTileEntity.java | 39 ++++++++++++++--- 8 files changed, 102 insertions(+), 38 deletions(-) (limited to 'src/main/java') diff --git a/.gitignore b/.gitignore index 406c4db8dc..5199bf1eeb 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ GregTech.cfg options.txt GregTech.lang mods/ +classes/ +logs/ diff --git a/AVRcore b/AVRcore index ec8467a08f..abd28835fb 160000 --- a/AVRcore +++ b/AVRcore @@ -1 +1 @@ -Subproject commit ec8467a08fff8b340a5ef698bdf6dc1915b3382a +Subproject commit abd28835fb49e03e6d08d4f2056ff671693fe671 diff --git a/build.gradle b/build.gradle index 401720ebb4..be661517e1 100644 --- a/build.gradle +++ b/build.gradle @@ -110,7 +110,7 @@ task getGregTech(type: Download) { task submodulesUpdate(type: Exec) { description 'Updates (and inits) git submodules' - commandLine 'git', 'submodule', 'update', '--init', '--recursive' + commandLine 'git', 'submodule', 'update', '--init', '--recursive','--remote' group 'Build Setup' } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java index 63642d6dbd..24033ba945 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java @@ -18,7 +18,7 @@ import java.util.Map; import static com.github.technus.tectech.Util.areBitsSet; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.cPrimitiveDefinition.null__; -import static com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM.stacksRegistered; +import static com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM.STACKS_REGISTERED; import static com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_scanner.*; /** @@ -68,7 +68,7 @@ public abstract class cElementalPrimitive extends cElementalDefinition { if (bindsBO.put(ID, this) != null) { Minecraft.getMinecraft().crashed(new CrashReport("Primitive definition", new tElementalException("Duplicate ID"))); } - stacksRegistered.add(this); + STACKS_REGISTERED.add(this); } // diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/transformations/bTransformationInfo.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/transformations/bTransformationInfo.java index d0c0bf04aa..c23894d6b1 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/transformations/bTransformationInfo.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/transformations/bTransformationInfo.java @@ -11,7 +11,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.HashMap; -import static com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM.stacksRegistered; +import static com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM.STACKS_REGISTERED; /** * Created by Tec on 26.05.2017. @@ -41,22 +41,22 @@ public class bTransformationInfo { public void addFluid(iHasElementalDefinition em, FluidStack fluidStack){ fluidQuantization.put(fluidStack.getFluidID(),new aFluidQuantizationInfo(fluidStack,em)); fluidDequantization.put(em.getDefinition(),new aFluidDequantizationInfo(em,fluidStack)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addFluid(iHasElementalDefinition em ,int fluidID,int fluidAmount) { fluidQuantization.put(fluidID,new aFluidQuantizationInfo(fluidID,fluidAmount,em)); fluidDequantization.put(em.getDefinition(),new aFluidDequantizationInfo(em,fluidID,fluidAmount)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addFluid(iHasElementalDefinition em, Fluid fluid, int fluidAmount){ fluidQuantization.put(fluid.getID(),new aFluidQuantizationInfo(fluid,fluidAmount,em)); fluidDequantization.put(em.getDefinition(),new aFluidDequantizationInfo(em,fluid,fluidAmount)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } private void addItemQuantization(aItemQuantizationInfo aIQI){ @@ -66,42 +66,42 @@ public class bTransformationInfo { public void addItem(iHasElementalDefinition em, ItemStack itemStack, boolean skipNBT){ addItemQuantization(new aItemQuantizationInfo(itemStack,skipNBT,em)); itemDequantization.put(em.getDefinition(),new aItemDequantizationInfo(em,itemStack)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addItem(iHasElementalDefinition em, OrePrefixes prefix, Materials material, int amount, boolean skipNBT){ addItemQuantization(new aItemQuantizationInfo(prefix,material,amount,skipNBT,em)); itemDequantization.put(em.getDefinition(),new aItemDequantizationInfo(em,prefix,material,amount)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addOredict(iHasElementalDefinition em, int id, int qty){ oredictQuantization.put(id,new aOredictQuantizationInfo(id,qty,em)); oredictDequantization.put(em.getDefinition(),new aOredictDequantizationInfo(em,id,qty)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addOredict(iHasElementalDefinition em, String name, int qty){ oredictQuantization.put(OreDictionary.getOreID(name),new aOredictQuantizationInfo(name,qty,em)); oredictDequantization.put(em.getDefinition(),new aOredictDequantizationInfo(em,name,qty)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addOredict(iHasElementalDefinition em, OrePrefixes prefix, Materials material, int qty){ oredictQuantization.put(OreDictionary.getOreID(prefix.name() + material.mName),new aOredictQuantizationInfo(prefix,material,qty,em)); oredictDequantization.put(em.getDefinition(),new aOredictDequantizationInfo(em,prefix,material,qty)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } public void addOredict(iHasElementalDefinition em, OrePrefixes prefix, String materialName, int qty){ oredictQuantization.put(OreDictionary.getOreID(prefix.name() + materialName),new aOredictQuantizationInfo(prefix,materialName,qty,em)); oredictDequantization.put(em.getDefinition(),new aOredictDequantizationInfo(em,prefix,materialName,qty)); - stacksRegistered.add(em.getDefinition()); - stacksRegistered.add(em.getDefinition().getAnti()); + STACKS_REGISTERED.add(em.getDefinition()); + STACKS_REGISTERED.add(em.getDefinition().getAnti()); } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java index a1380526eb..1e80c6f1e8 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java @@ -12,12 +12,16 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.templates.iElem import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.*; import com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.eBosonDefinition; import com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.eQuarkDefinition; +import com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; import static com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.dComplexAspectDefinition.getNbtTagCompound; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; @@ -34,6 +38,8 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi private static final byte nbtType = (byte) 'h'; //Helpers + public static final Map SYMBOL_MAP =new HashMap<>(); + public static final Map NAME_MAP =new HashMap<>(); public static dHadronDefinition hadron_p, hadron_n, hadron_p_, hadron_n_; public static cElementalDefinitionStack hadron_p1, hadron_n1, hadron_p2, hadron_n2, hadron_p3, hadron_n3, hadron_p5; private static float protonMass = 0F; @@ -137,8 +143,13 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi public String getName() { StringBuilder name= new StringBuilder(getSimpleName()); name.append(':'); - for (cElementalDefinitionStack quark : quarkStacks.values()) { - name.append(' ').append(quark.definition.getSymbol()).append(quark.amount); + String sym= NAME_MAP.get(this); + if(sym!=null){ + name.append(' ').append(sym); + }else { + for (cElementalDefinitionStack quark : quarkStacks.values()) { + name.append(' ').append(quark.definition.getSymbol()).append(quark.amount); + } } return name.toString(); } @@ -163,9 +174,14 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi @Override public String getSymbol() { StringBuilder symbol = new StringBuilder(8); - for (cElementalDefinitionStack quark : quarkStacks.values()) { - for (int i = 0; i < quark.amount; i++) { - symbol.append(quark.definition.getSymbol()); + String sym=SYMBOL_MAP.get(this); + if(sym!=null){ + symbol.append(sym); + }else { + for (cElementalDefinitionStack quark : quarkStacks.values()) { + for (int i = 0; i < quark.amount; i++) { + symbol.append(quark.definition.getSymbol()); + } } } return symbol.toString(); @@ -174,9 +190,14 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi @Override public String getShortSymbol() { StringBuilder symbol = new StringBuilder(8); - for (cElementalDefinitionStack quark : quarkStacks.values()) { - for (int i = 0; i < quark.amount; i++) { - symbol.append(quark.definition.getShortSymbol()); + String sym=SYMBOL_MAP.get(this); + if(sym!=null){ + symbol.append(sym); + }else { + for (cElementalDefinitionStack quark : quarkStacks.values()) { + for (int i = 0; i < quark.amount; i++) { + symbol.append(quark.definition.getShortSymbol()); + } } } return symbol.toString(); @@ -391,12 +412,24 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi protonMass = hadron_p.mass; //redefine the proton with proper lifetime (the lifetime is based on mass comparison) hadron_p = new dHadronDefinition(new cElementalDefinitionStackMap(eQuarkDefinition.quark_u.getStackForm(2), eQuarkDefinition.quark_d.getStackForm(1))); + SYMBOL_MAP.put(hadron_p,"p"); + NAME_MAP.put(hadron_p,"Proton"); + DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_p); hadron_p_ = (dHadronDefinition) hadron_p.getAnti(); + SYMBOL_MAP.put(hadron_p_,"~p"); + NAME_MAP.put(hadron_p_,"Anti Proton"); + DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_p_); hadron_n = new dHadronDefinition(new cElementalDefinitionStackMap(eQuarkDefinition.quark_u.getStackForm(1), eQuarkDefinition.quark_d.getStackForm(2))); neutronMass = hadron_n.mass; //redefine the neutron with proper lifetime (the lifetime is based on mass comparison) hadron_n = new dHadronDefinition(new cElementalDefinitionStackMap(eQuarkDefinition.quark_u.getStackForm(1), eQuarkDefinition.quark_d.getStackForm(2))); + SYMBOL_MAP.put(hadron_n, "n"); + NAME_MAP.put(hadron_n, "Neutron"); + DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_p); hadron_n_ = (dHadronDefinition) hadron_n.getAnti(); + SYMBOL_MAP.put(hadron_n_,"~n"); + NAME_MAP.put(hadron_n_,"Anti Neutron"); + DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_p_); } catch (tElementalException e) { if (DEBUG_MODE) { e.printStackTrace(); 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 3eb71abca1..286b21f4e2 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 @@ -34,7 +34,7 @@ import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; * Created by Tec on 15.03.2017. */ public final class DebugElementalInstanceContainer_EM extends Item implements IElementalItem { - public static final TreeSet stacksRegistered=new TreeSet<>(); + public static final TreeSet STACKS_REGISTERED =new TreeSet<>(); public static DebugElementalInstanceContainer_EM INSTANCE; @@ -135,7 +135,7 @@ public final class DebugElementalInstanceContainer_EM extends Item implements IE ItemStack that = new ItemStack(this, 1); that.setTagCompound(new NBTTagCompound()); list.add(that); - for(iElementalDefinition defintion:stacksRegistered){ + for(iElementalDefinition defintion: STACKS_REGISTERED){ list.add(setContent(new ItemStack(this).setStackDisplayName(defintion.getName()+" x"+1),new cElementalInstanceStackMap(new cElementalInstanceStack(defintion,1)))); list.add(setContent(new ItemStack(this).setStackDisplayName(defintion.getName()+" x"+144),new cElementalInstanceStackMap(new cElementalInstanceStack(defintion,144)))); list.add(setContent(new ItemStack(this).setStackDisplayName(defintion.getName()+" x"+1000),new cElementalInstanceStackMap(new cElementalInstanceStack(defintion,1000)))); diff --git a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java index 798a2daa47..d4cb8afb0f 100644 --- a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java +++ b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java @@ -1,17 +1,43 @@ package com.github.technus.tectech.thing.tileEntity; +import com.github.technus.avrClone.AvrCore; +import com.github.technus.avrClone.instructions.InstructionRegistry; +import com.github.technus.avrClone.memory.program.ProgramMemory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class MicroControllerTileEntity extends TileEntity { + public final AvrCore core; + + public MicroControllerTileEntity(){ + core=new AvrCore(InstructionRegistry.INSTRUCTION_REGISTRY_OP,false); + } + @Override - public void readFromNBT(NBTTagCompound p_145839_1_) { - super.readFromNBT(p_145839_1_); + public void readFromNBT(NBTTagCompound tag) { + super.readFromNBT(tag); + core.programCounter=tag.getInteger("programCounter"); + if(core.getProgramMemory()!=null){ + ProgramMemory programMemory=core.getProgramMemory(); + NBTTagCompound program=new NBTTagCompound(); + program.setIntArray("instructions",programMemory.instructions); + program.setIntArray("param0",programMemory.param0); + program.setIntArray("param1",programMemory.param1); + tag.setTag("program",program); + } } @Override - public void writeToNBT(NBTTagCompound p_145841_1_) { - super.writeToNBT(p_145841_1_); + public void writeToNBT(NBTTagCompound tag) { + super.writeToNBT(tag); + tag.setInteger("programCounter",core.programCounter); + if(tag.hasKey("program")){ + NBTTagCompound program=tag.getCompoundTag("program"); + int[] instructions=program.getIntArray("instructions"); + int[] param0=program.getIntArray("param0"); + int[] param1=program.getIntArray("param1"); + //core.setProgramMemory(new ProgramMemory(instructions,param0,param1,core.getInstructionRegistry())); + } } @Override @@ -21,6 +47,9 @@ public class MicroControllerTileEntity extends TileEntity { @Override public void updateEntity() { - super.updateEntity(); + super.updateEntity(); + if(core.checkValid()){ + + } } } -- cgit From ac202599529ef2067e4db66faaf76dd71dbafd86 Mon Sep 17 00:00:00 2001 From: Technus Date: Tue, 23 Jul 2019 18:31:40 +0200 Subject: Properly add to registered definitions --- .../definitions/complex/dHadronDefinition.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java index 1e80c6f1e8..404f116adf 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java @@ -173,34 +173,34 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi @Override public String getSymbol() { - StringBuilder symbol = new StringBuilder(8); String sym=SYMBOL_MAP.get(this); if(sym!=null){ - symbol.append(sym); + return sym; }else { + StringBuilder symbol = new StringBuilder(8); for (cElementalDefinitionStack quark : quarkStacks.values()) { for (int i = 0; i < quark.amount; i++) { symbol.append(quark.definition.getSymbol()); } } + return symbol.toString(); } - return symbol.toString(); } @Override public String getShortSymbol() { - StringBuilder symbol = new StringBuilder(8); String sym=SYMBOL_MAP.get(this); if(sym!=null){ - symbol.append(sym); + return sym; }else { + StringBuilder symbol = new StringBuilder(8); for (cElementalDefinitionStack quark : quarkStacks.values()) { for (int i = 0; i < quark.amount; i++) { symbol.append(quark.definition.getShortSymbol()); } } + return symbol.toString(); } - return symbol.toString(); } @Override @@ -425,11 +425,11 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi hadron_n = new dHadronDefinition(new cElementalDefinitionStackMap(eQuarkDefinition.quark_u.getStackForm(1), eQuarkDefinition.quark_d.getStackForm(2))); SYMBOL_MAP.put(hadron_n, "n"); NAME_MAP.put(hadron_n, "Neutron"); - DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_p); + DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_n); hadron_n_ = (dHadronDefinition) hadron_n.getAnti(); SYMBOL_MAP.put(hadron_n_,"~n"); NAME_MAP.put(hadron_n_,"Anti Neutron"); - DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_p_); + DebugElementalInstanceContainer_EM.STACKS_REGISTERED.add(hadron_n_); } catch (tElementalException e) { if (DEBUG_MODE) { e.printStackTrace(); -- cgit From 382d9a8d17961930497490b8e46c941d83305461 Mon Sep 17 00:00:00 2001 From: Technus Date: Wed, 24 Jul 2019 00:36:51 +0200 Subject: Fix enable alpha. --- src/main/java/com/github/technus/tectech/font/TecTechFontRender.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/font/TecTechFontRender.java b/src/main/java/com/github/technus/tectech/font/TecTechFontRender.java index a7130bab90..4aea8bce92 100644 --- a/src/main/java/com/github/technus/tectech/font/TecTechFontRender.java +++ b/src/main/java/com/github/technus/tectech/font/TecTechFontRender.java @@ -212,13 +212,13 @@ public class TecTechFontRender extends FontRenderer { } private int drawStringFront(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_) { - enableAlpha(); + GL11.glEnable(3008); resetStyles2(); return renderString2(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false); } private int drawStringBack(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_) { - enableAlpha(); + GL11.glEnable(3008); resetStyles2(); return renderString2(p_85187_1_, p_85187_2_ + 1, p_85187_3_ + 1, p_85187_4_, true); } -- cgit From 42f082bc0bc3f27775ea3a3f45995487e93a6d5e Mon Sep 17 00:00:00 2001 From: Technus Date: Wed, 24 Jul 2019 01:09:42 +0200 Subject: Adjust parametrizer card --- .../tectech/thing/item/ParametrizerMemoryCard.java | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java b/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java index dafc425163..b13ef6b574 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java @@ -3,6 +3,7 @@ package com.github.technus.tectech.thing.item; import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.Util; import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_Param; +import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_ParamText; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; @@ -64,6 +65,8 @@ public final class ParametrizerMemoryCard extends Item { tNBT.setInteger("param", parametrizer.param); tNBT.setDouble("value0D", parametrizer.value0D); tNBT.setDouble("value1D", parametrizer.value1D); + tNBT.removeTag("value0s"); + tNBT.removeTag("value1s"); } return true; }else if(metaTE instanceof GT_MetaTileEntity_MultiblockBase_EM){ @@ -79,6 +82,28 @@ public final class ParametrizerMemoryCard extends Item { tNBT.getDouble("value1D")); return true; } + } else if (metaTE instanceof GT_MetaTileEntity_Hatch_ParamText) { + GT_MetaTileEntity_Hatch_ParamText parametrizer = (GT_MetaTileEntity_Hatch_ParamText) metaTE; + if (aStack.getTagCompound() == null) { + aStack.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound tNBT = aStack.getTagCompound(); + if (aStack.getItemDamage() == 1) { + //write to parametrizer + parametrizer.param = tNBT.getInteger("param"); + parametrizer.value0D = tNBT.getDouble("value0D"); + parametrizer.value1D = tNBT.getDouble("value1D"); + parametrizer.value0s = tNBT.getString("value0s"); + parametrizer.value1s = tNBT.getString("value1s"); + } else { + //read from parametrizer + tNBT.setInteger("param", parametrizer.param); + tNBT.setDouble("value0D", parametrizer.value0D); + tNBT.setDouble("value1D", parametrizer.value1D); + tNBT.setString("value0s", parametrizer.value0s); + tNBT.setString("value1s", parametrizer.value1s); + } + return true; } } } @@ -113,16 +138,21 @@ public final class ParametrizerMemoryCard extends Item { } aList.add(EnumChatFormatting.BLUE + "Sneak right click to lock/unlock"); - long temp; + double temp; if(tNBT!=null && tNBT.hasKey("param")) { aList.add("Hatch ID: "+EnumChatFormatting.AQUA + tNBT.getInteger("param")); temp=tNBT.getInteger("value0D"); aList.add("Value 0D: "+EnumChatFormatting.AQUA + temp); aList.add("Value 0B: "+EnumChatFormatting.AQUA + Util.longBitsToShortString(Double.doubleToLongBits(temp))); + if(tNBT.hasKey("value0s")) { + aList.add("Value 0s: " + EnumChatFormatting.AQUA + tNBT.getString("value0s")); + } temp=tNBT.getInteger("value1D"); aList.add("Value 1D: "+EnumChatFormatting.AQUA + temp); aList.add("Value 1B: "+EnumChatFormatting.AQUA + Util.longBitsToShortString(Double.doubleToLongBits(temp))); - aList.add("Uses Floats: "+(tNBT.getBoolean("usesFloats")?EnumChatFormatting.GREEN+"TRUE":EnumChatFormatting.RED+"FALSE")); + if(tNBT.hasKey("value1s")) { + aList.add("Value 1s: " + EnumChatFormatting.AQUA + tNBT.getString("value1s")); + } } } -- cgit From 9c0ed5651b40d644a9ec9c961baf4cdd66402eb9 Mon Sep 17 00:00:00 2001 From: Technus Date: Wed, 24 Jul 2019 13:10:31 +0200 Subject: persistence? --- AVRcore | 2 +- .../tileEntity/MicroControllerTileEntity.java | 63 ++++++++++++++++------ 2 files changed, 47 insertions(+), 18 deletions(-) (limited to 'src/main/java') diff --git a/AVRcore b/AVRcore index abd28835fb..4c0bd1b374 160000 --- a/AVRcore +++ b/AVRcore @@ -1 +1 @@ -Subproject commit abd28835fb49e03e6d08d4f2056ff671693fe671 +Subproject commit 4c0bd1b3744bc0c328990266f1f910c438c7abd9 diff --git a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java index d4cb8afb0f..394f1272dc 100644 --- a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java +++ b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java @@ -1,42 +1,63 @@ package com.github.technus.tectech.thing.tileEntity; import com.github.technus.avrClone.AvrCore; +import com.github.technus.avrClone.instructions.ExecutionEvent; import com.github.technus.avrClone.instructions.InstructionRegistry; +import com.github.technus.avrClone.memory.EepromMemory; +import com.github.technus.avrClone.memory.RemovableMemory; import com.github.technus.avrClone.memory.program.ProgramMemory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class MicroControllerTileEntity extends TileEntity { - public final AvrCore core; + private final AvrCore core; + private int[] tempData; public MicroControllerTileEntity(){ - core=new AvrCore(InstructionRegistry.INSTRUCTION_REGISTRY_OP,false); + 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); } } @@ -48,8 +69,16 @@ public class MicroControllerTileEntity extends TileEntity { @Override public void updateEntity() { super.updateEntity(); - if(core.checkValid()){ - + if (tempData != null) { + //todo discovery of components + core.dataMemory = tempData; + tempData = null; + } + for (int i = 0, cycles = Math.min(1 << getBlockMetadata(), 512); i < cycles; i++) { + ExecutionEvent executionEvent = core.cpuCycle(); + if (executionEvent != null) { + break; + } } } } -- cgit From 4979e5460a6edeabfb089b1af9f00337952bf65f Mon Sep 17 00:00:00 2001 From: Technus Date: Wed, 24 Jul 2019 22:50:18 +0200 Subject: this should make the microcontroller chooch --- AVRcore | 2 +- .../tileEntity/MicroControllerTileEntity.java | 42 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) (limited to 'src/main/java') diff --git a/AVRcore b/AVRcore index 4c0bd1b374..10a9ecd8c3 160000 --- a/AVRcore +++ b/AVRcore @@ -1 +1 @@ -Subproject commit 4c0bd1b3744bc0c328990266f1f910c438c7abd9 +Subproject commit 10a9ecd8c3ab6de7acf8c32f53f668373e0ea576 diff --git a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java index 394f1272dc..3167bf820d 100644 --- a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java +++ b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java @@ -2,16 +2,25 @@ package com.github.technus.tectech.thing.tileEntity; 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 net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class MicroControllerTileEntity extends TileEntity { + static { + Instruction.random= TecTech.RANDOM; + } private final AvrCore core; private int[] tempData; + private boolean debugRun; + private int delay; public MicroControllerTileEntity(){ core=new AvrCore(); @@ -24,6 +33,10 @@ public class MicroControllerTileEntity extends TileEntity { @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); + debugRun=tag.getBoolean("debugRun"); + delay=tag.getInteger("delay"); + core.active =tag.getBoolean("active"); + core.awoken=(tag.getBoolean("awoken")); core.programCounter=tag.getInteger("programCounter"); if(tag.hasKey("instructions")){ int[] instructions=tag.getIntArray("instructions"); @@ -45,6 +58,10 @@ public class MicroControllerTileEntity extends TileEntity { @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); + tag.setBoolean("debugRun",debugRun); + tag.setInteger("delay",delay); + tag.setBoolean("active",core.active); + tag.setBoolean("awoken",core.awoken); tag.setInteger("programCounter",core.programCounter); ProgramMemory programMemory=core.getProgramMemory(); if(programMemory!=null){ @@ -74,10 +91,27 @@ public class MicroControllerTileEntity extends TileEntity { core.dataMemory = tempData; tempData = null; } - for (int i = 0, cycles = Math.min(1 << getBlockMetadata(), 512); i < cycles; i++) { - ExecutionEvent executionEvent = core.cpuCycle(); - if (executionEvent != null) { - break; + if (core.active) { + core.interruptsHandle(); + if (core.awoken) { + delay=0; + for (int i = 0, cycles = Math.min(1 << getBlockMetadata(), 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; + } } } } -- cgit From 43a29dfc84e140ed6a4a93ded52aa2d44faf6612 Mon Sep 17 00:00:00 2001 From: Technus Date: Fri, 26 Jul 2019 11:27:47 +0200 Subject: Fix creative tab item registration --- .../com/github/technus/tectech/loader/MainLoader.java | 8 ++------ .../technus/tectech/loader/gui/CreativeTabTecTech.java | 16 ---------------- .../technus/tectech/thing/block/QuantumGlassBlock.java | 2 ++ .../technus/tectech/thing/casing/GT_Block_CasingsNH.java | 3 +++ .../technus/tectech/thing/casing/GT_Block_CasingsTT.java | 3 +++ .../technus/tectech/thing/casing/GT_Block_HintTT.java | 3 +++ .../tectech/thing/item/ConstructableTriggerItem.java | 2 ++ .../thing/item/DebugElementalInstanceContainer_EM.java | 2 ++ .../thing/item/ElementalDefinitionScanStorage_EM.java | 2 ++ .../tectech/thing/item/ParametrizerMemoryCard.java | 2 ++ 10 files changed, 21 insertions(+), 22 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/loader/MainLoader.java b/src/main/java/com/github/technus/tectech/loader/MainLoader.java index b45e8bd532..7a9ab2cdb6 100644 --- a/src/main/java/com/github/technus/tectech/loader/MainLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/MainLoader.java @@ -60,6 +60,7 @@ public final class MainLoader { } public static void preLoad(){ + creativeTabTecTech =new CreativeTabTecTech("TecTech"); //set expanded texture arrays for tiers try { @@ -115,7 +116,7 @@ public final class MainLoader { } public static void postLoad() { - ProgressManager.ProgressBar progressBarPostLoad = ProgressManager.push("TecTech Post Loader", 6); + ProgressManager.ProgressBar progressBarPostLoad = ProgressManager.push("TecTech Post Loader", 5); progressBarPostLoad.step("Dreamcraft Compatibility"); if(Loader.isModLoaded(Reference.DREAMCRAFT)){ @@ -141,13 +142,8 @@ public final class MainLoader { progressBarPostLoad.step("Recipes"); new RecipeLoader().run(); - TecTech.LOGGER.info("Recipe Init Done"); - progressBarPostLoad.step("Creative Tab"); - creativeTabTecTech =new CreativeTabTecTech("TecTech"); - TecTech.LOGGER.info("CreativeTab initiation complete"); - progressBarPostLoad.step("Register Extra Hazmat Suits"); registerExtraHazmats(); TecTech.LOGGER.info("Hazmat additions done"); diff --git a/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java b/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java index 295e1aeb7d..d360162fb6 100644 --- a/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java +++ b/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java @@ -1,12 +1,7 @@ package com.github.technus.tectech.loader.gui; import com.github.technus.tectech.thing.CustomItemList; -import com.github.technus.tectech.thing.block.QuantumGlassBlock; -import com.github.technus.tectech.thing.casing.TT_Container_Casings; -import com.github.technus.tectech.thing.item.ConstructableTriggerItem; import com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM; -import com.github.technus.tectech.thing.item.ElementalDefinitionScanStorage_EM; -import com.github.technus.tectech.thing.item.ParametrizerMemoryCard; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; @@ -20,7 +15,6 @@ public class CreativeTabTecTech extends CreativeTabs { public CreativeTabTecTech(String name) { super(name); - registerThingsInTabs(); } @SideOnly(Side.CLIENT) @@ -38,14 +32,4 @@ public class CreativeTabTecTech extends CreativeTabs { } super.displayAllReleventItems(stuffToShow); } - - private static void registerThingsInTabs() { - QuantumGlassBlock.INSTANCE.setCreativeTab(creativeTabTecTech); - TT_Container_Casings.sBlockCasingsTT.setCreativeTab(creativeTabTecTech); - TT_Container_Casings.sHintCasingsTT.setCreativeTab(creativeTabTecTech); - DebugElementalInstanceContainer_EM.INSTANCE.setCreativeTab(creativeTabTecTech); - ConstructableTriggerItem.INSTANCE.setCreativeTab(creativeTabTecTech); - ParametrizerMemoryCard.INSTANCE.setCreativeTab(creativeTabTecTech); - ElementalDefinitionScanStorage_EM.INSTANCE.setCreativeTab(creativeTabTecTech); - } } diff --git a/src/main/java/com/github/technus/tectech/thing/block/QuantumGlassBlock.java b/src/main/java/com/github/technus/tectech/thing/block/QuantumGlassBlock.java index 1a08bdbeec..d34d12c754 100644 --- a/src/main/java/com/github/technus/tectech/thing/block/QuantumGlassBlock.java +++ b/src/main/java/com/github/technus/tectech/thing/block/QuantumGlassBlock.java @@ -13,6 +13,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; /** * Created by danie_000 on 17.12.2016. @@ -32,6 +33,7 @@ public final class QuantumGlassBlock extends BlockBase { setLightOpacity(0); setStepSound(Block.soundTypeMetal); setBlockTextureName(MODID + ":blockQuantumGlass"); + setCreativeTab(creativeTabTecTech); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsNH.java b/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsNH.java index 78b0a2a6a9..bac2dfb9ac 100644 --- a/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsNH.java +++ b/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsNH.java @@ -10,6 +10,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; import static com.github.technus.tectech.thing.metaTileEntity.Textures.*; /** @@ -21,6 +22,8 @@ public class GT_Block_CasingsNH public GT_Block_CasingsNH() { super(GT_Item_CasingsNH.class, "gt.blockcasingsNH", GT_Material_Casings.INSTANCE); + setCreativeTab(creativeTabTecTech); + for (byte b = 0; b < 16; b = (byte) (b + 1)) { Textures.BlockIcons.casingTexturePages[8][b+64] = new GT_CopiedBlockTexture(this, 6, b); /*IMPORTANT for block recoloring*/ diff --git a/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsTT.java b/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsTT.java index 2ea22b625d..09dc49b5a5 100644 --- a/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsTT.java +++ b/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsTT.java @@ -18,6 +18,7 @@ import net.minecraft.world.IBlockAccess; import java.util.List; import static com.github.technus.tectech.TecTech.tectechTexturePage1; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; /** * Created by danie_000 on 03.10.2016. @@ -30,6 +31,8 @@ public class GT_Block_CasingsTT extends GT_Block_Casings_Abstract { public GT_Block_CasingsTT() { super(GT_Item_CasingsTT.class, "gt.blockcasingsTT", GT_Material_Casings.INSTANCE); + setCreativeTab(creativeTabTecTech); + for (byte b = 0; b < 16; b = (byte) (b + 1)) { Textures.BlockIcons.casingTexturePages[texturePage][b] = new GT_CopiedBlockTexture(this, 6, b); /*IMPORTANT for block recoloring**/ diff --git a/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_HintTT.java b/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_HintTT.java index dc9e809b46..c65870eeb7 100644 --- a/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_HintTT.java +++ b/src/main/java/com/github/technus/tectech/thing/casing/GT_Block_HintTT.java @@ -16,6 +16,8 @@ import net.minecraft.world.IBlockAccess; import java.util.List; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; + /** * Created by danie_000 on 03.10.2016. */ @@ -24,6 +26,7 @@ public class GT_Block_HintTT extends GT_Block_Casings_Abstract { public GT_Block_HintTT() { super(GT_Item_HintTT.class, "gt.blockhintTT", GT_Material_Casings.INSTANCE); + setCreativeTab(creativeTabTecTech); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".0.name", "Hint 1 dot");//id is -1 GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".1.name", "Hint 2 dots"); diff --git a/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java b/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java index 33f0d34ad5..57f3bbade1 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java @@ -24,6 +24,7 @@ import java.util.List; import static com.github.technus.tectech.Reference.MODID; import static com.github.technus.tectech.Util.StructureBuilder; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; import static gregtech.api.GregTech_API.sBlockCasings1; /** @@ -37,6 +38,7 @@ public final class ConstructableTriggerItem extends Item { private ConstructableTriggerItem() { setUnlocalizedName("em.constructable"); setTextureName(MODID + ":itemConstructable"); + setCreativeTab(creativeTabTecTech); } @Override 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 286b21f4e2..3b09d37a33 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 @@ -29,6 +29,7 @@ import java.util.TreeSet; 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. @@ -42,6 +43,7 @@ public final class DebugElementalInstanceContainer_EM extends Item implements IE setMaxStackSize(1); setUnlocalizedName("em.debugContainer"); setTextureName(MODID + ":itemDebugContainer"); + setCreativeTab(creativeTabTecTech); } @Override 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 564209062a..87b76696bb 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 @@ -25,6 +25,7 @@ import net.minecraft.world.World; 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. @@ -37,6 +38,7 @@ public final class ElementalDefinitionScanStorage_EM extends Item implements IEl setMaxStackSize(1); setUnlocalizedName("em.definitionScanStorage"); setTextureName(MODID + ":itemDefinitionScanStorage"); + setCreativeTab(creativeTabTecTech); } //return previous thing diff --git a/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java b/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java index b13ef6b574..c12d2707c6 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java @@ -25,6 +25,7 @@ import net.minecraft.world.World; import java.util.List; import static com.github.technus.tectech.Reference.MODID; +import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; import static com.github.technus.tectech.thing.CustomItemList.parametrizerMemory; /** @@ -39,6 +40,7 @@ public final class ParametrizerMemoryCard extends Item { setHasSubtypes(true); setUnlocalizedName("em.parametrizerMemoryCard"); setTextureName(MODID + ":itemParametrizerMemoryCardUnlocked"); + setCreativeTab(creativeTabTecTech); } @Override -- cgit From 2bfa7ba4d4782c5490302d737950846afd6fad22 Mon Sep 17 00:00:00 2001 From: Technus Date: Sat, 27 Jul 2019 16:22:04 +0200 Subject: probably working avr core --- AVRcore | 2 +- .../tectech/mechanics/avr/SidedRedstone.java | 248 +++++++++++++++++++++ .../single/GT_MetaTileEntity_DataReader.java | 2 +- ...T_MetaTileEntity_MicroControllerTileEntity.java | 169 ++++++++++++++ .../tileEntity/MicroControllerTileEntity.java | 118 ---------- 5 files changed, 419 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroControllerTileEntity.java delete mode 100644 src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java (limited to 'src/main/java') diff --git a/AVRcore b/AVRcore index 10a9ecd8c3..8d3164d327 160000 --- a/AVRcore +++ b/AVRcore @@ -1 +1 @@ -Subproject commit 10a9ecd8c3ab6de7acf8c32f53f668373e0ea576 +Subproject commit 8d3164d327ab3d2e0d30c6bb07a974cb4ed4e21a 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 new file mode 100644 index 0000000000..9488b9280f --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java @@ -0,0 +1,248 @@ +package com.github.technus.tectech.mechanics.avr; + +import com.github.technus.avrClone.AvrCore; +import com.github.technus.avrClone.registerPackages.*; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public class SidedRedstone extends RegisterPackageSync { + public static final RSINT RSINT =new RSINT(); + + public SidedRedstone(int offset) { + super(offset, 23); + addRegisters(Register.values()); + addBits(RegisterBitsPCMSK.values()); + addBits(RegisterBitsPCFR.values()); + addBits(RegisterBitsPCINT.values()); + addBits(RegisterBitsPNEW.values()); + addBits(RegisterBitsPOLD.values()); + addInterrupts(RSINT); + } + + @Override + public void preSync(AvrCore core,IGregTechTileEntity iGregTechTileEntity) { + int addr=this.getOffset(); + int sides=0; + for(byte i=0;i<6;i++){ + int val=iGregTechTileEntity.getInternalInputRedstoneSignal(i); + sides|=(val > 0?1:0)< 0) { + if (core.getDataBitsOr(Register.PCINT.getAddress(this), RegisterBitsPCINT.PCEN.mask)) { + core.setDataBits(Register.PCINT.getAddress(this), RegisterBitsPCINT.PCIF.mask); + } + } + } + } + + @Override + public void postSync(AvrCore core,IGregTechTileEntity iGregTechTileEntity) { + int addr=this.getOffset(); + for(byte i=0;i<6;i++){ + iGregTechTileEntity.setOutputRedstoneSignal(i,(byte)core.getDataValue(addr));//allows edge detection hack? + addr+=3; + } + } + + public enum Register implements IRegister{ + PIN0,PINT0,PORT0, + PIN1,PINT1,PORT1, + PIN2,PINT2,PORT2, + PIN3,PINT3,PORT3, + PIN4,PINT4,PORT4, + PIN5,PINT5,PORT5, + PCMSK,PCFR,PCINT,PNEW,POLD; + + public final int relativeOffset; + + Register(){ + this.relativeOffset =ordinal(); + } + + @Override + public int getAddress(SidedRedstone registerPackage) { + return registerPackage.getOffset()+relativeOffset; + } + } + + public enum RegisterBitsPCMSK implements IRegisterBit{ + PCINT0,PCINT1,PCINT2,PCINT3,PCINT4,PCINT5; + + private final int bit,mask; + + RegisterBitsPCMSK(){ + bit=ordinal(); + mask=1<{ + PCF0,PCF1,PCF2,PCF3,PCF4,PCF5; + + private final int bit,mask; + + RegisterBitsPCFR(){ + bit=ordinal(); + mask=1<{ + PCIF,PCEN,PCISC0,PCISC1; + + private final int bit,mask; + + RegisterBitsPCINT(){ + bit=ordinal(); + mask=1<{ + PNEW0,PNEW1,PNEW2,PNEW3,PNEW4,PNEW5; + + private final int bit,mask; + + RegisterBitsPNEW(){ + bit=ordinal(); + mask=1<{ + POLD0,POLD1,POLD2,POLD3,POLD4,POLD5; + + private final int bit,mask; + + RegisterBitsPOLD(){ + bit=ordinal(); + mask=1<{ + @Override + public int getVector() { + return 1; + } + + @Override + public boolean getTrigger(AvrCore core, SidedRedstone registerPackage) { + return (core.getDataValue(Register.PCINT.getAddress(registerPackage))&1)==1; + } + + @Override + public void setTrigger(AvrCore core, SidedRedstone registerPackage, boolean value) { + int val=core.getDataValue(Register.PCINT.getAddress(registerPackage)); + core.setDataValue(Register.PCINT.getAddress(registerPackage), + value?val|RegisterBitsPCINT.PCIF.mask:val&~RegisterBitsPCINT.PCIF.mask); + } + + @Override + public String name() { + return "RSINT"; + } + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java index d8b230995f..6d594512bd 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java @@ -39,7 +39,7 @@ import static com.github.technus.tectech.recipe.TT_recipeAdder.nullItem; */ public class GT_MetaTileEntity_DataReader extends GT_MetaTileEntity_BasicMachine { private static final HashMap> RENDER_REGISTRY =new HashMap<>(); - private static GT_RenderedTexture READER_ONLINE, READER_OFFLINE; + public static GT_RenderedTexture READER_ONLINE, READER_OFFLINE; public GT_MetaTileEntity_DataReader(int aID, String aName, String aNameRegional, int aTier) { super(aID,aName,aNameRegional,aTier,1,"Reads Data Sticks and Orbs",1,1,"dataReader.png",""); 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 new file mode 100644 index 0000000000..6692c19cea --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroControllerTileEntity.java @@ -0,0 +1,169 @@ +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; + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java deleted file mode 100644 index 3167bf820d..0000000000 --- a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.github.technus.tectech.thing.tileEntity; - -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 net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - -public class MicroControllerTileEntity extends TileEntity { - static { - Instruction.random= TecTech.RANDOM; - } - private final AvrCore core; - private int[] tempData; - private boolean debugRun; - private int delay; - - public MicroControllerTileEntity(){ - 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 invalidate() { - super.invalidate(); - } - - @Override - public void updateEntity() { - super.updateEntity(); - if (tempData != null) { - //todo discovery of components - core.dataMemory = tempData; - tempData = null; - } - if (core.active) { - core.interruptsHandle(); - if (core.awoken) { - delay=0; - for (int i = 0, cycles = Math.min(1 << getBlockMetadata(), 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; - } - } - } - } -} -- cgit From 80ea67fd7623535b30424b7618d69767b926c330 Mon Sep 17 00:00:00 2001 From: Technus Date: Tue, 30 Jul 2019 17:54:28 +0200 Subject: TEMP WORK --- AVRcore | 2 +- libs/OpenComputers-MC1.7.10-1.6.2.12-api.jar | Bin 268275 -> 0 bytes .../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 ---------------- 15 files changed, 471 insertions(+), 175 deletions(-) delete mode 100644 libs/OpenComputers-MC1.7.10-1.6.2.12-api.jar 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/AVRcore b/AVRcore index 8d3164d327..3bdcf87f6e 160000 --- a/AVRcore +++ b/AVRcore @@ -1 +1 @@ -Subproject commit 8d3164d327ab3d2e0d30c6bb07a974cb4ed4e21a +Subproject commit 3bdcf87f6ed02b9e5f9a291b3e534c5d515e573b diff --git a/libs/OpenComputers-MC1.7.10-1.6.2.12-api.jar b/libs/OpenComputers-MC1.7.10-1.6.2.12-api.jar deleted file mode 100644 index 5777d1ffdb..0000000000 Binary files a/libs/OpenComputers-MC1.7.10-1.6.2.12-api.jar and /dev/null differ 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 From 3bb13de2fcff5e2c142f424204d74eefbc581eeb Mon Sep 17 00:00:00 2001 From: Tec Date: Tue, 27 Aug 2019 22:03:20 +0200 Subject: Push so i dont lose it --- .../java/com/github/technus/tectech/Converter.java | 59 +++++ .../openComputers/AvrArchitecture.java | 267 +++++++++++++++++++++ .../technus/tectech/thing/item/AvrProgrammer.java | 7 +- 3 files changed, 329 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/Converter.java create mode 100644 src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/Converter.java b/src/main/java/com/github/technus/tectech/Converter.java new file mode 100644 index 0000000000..5d1f5c802e --- /dev/null +++ b/src/main/java/com/github/technus/tectech/Converter.java @@ -0,0 +1,59 @@ +package com.github.technus.tectech; + +import java.io.*; + +public final class Converter { + private Converter() {} + + public static void writeInts(int [] array,ByteArrayOutputStream byteArrayOutputStream) { + try { + DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + for (int i = 0; i < array.length; i++) { + dataOutputStream.writeInt(array[i]); + } + dataOutputStream.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static void readInts(ByteArrayInputStream byteArrayInputStream,int[] array) { + try { + DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream); + for (int i = 0; i < array.length; i++) { + array[i] = dataInputStream.readInt(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static byte[] writeInts(int[] array) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(array.length * 4); + DataOutputStream dos = new DataOutputStream(bos); + for (int i = 0; i < array.length; i++) { + dos.writeInt(array[i]); + } + + return bos.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static int[] readInts(byte[] array) { + try { + ByteArrayInputStream bis = new ByteArrayInputStream(array); + DataInputStream dataInputStream = new DataInputStream(bis); + int size = array.length / Integer.BYTES; + int[] res = new int[size]; + for (int i = 0; i < size; i++) { + res[i] = dataInputStream.readInt(); + } + return res; + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java b/src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java new file mode 100644 index 0000000000..fcbb65d609 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java @@ -0,0 +1,267 @@ +package com.github.technus.tectech.compatibility.openComputers; + +import com.github.technus.avrClone.AvrCore; +import com.github.technus.avrClone.instructions.ExecutionEvent; +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.Converter; +import com.github.technus.tectech.TecTech; +import li.cil.oc.Settings; +import li.cil.oc.api.Driver; +import li.cil.oc.api.driver.Item; +import li.cil.oc.api.driver.item.Memory; +import li.cil.oc.api.machine.Architecture; +import li.cil.oc.api.machine.ExecutionResult; +import li.cil.oc.api.machine.Machine; +import li.cil.oc.api.machine.Signal; +import li.cil.oc.common.SaveHandler; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import org.apache.commons.io.IOUtils; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +@Architecture.Name("AVR 32Bit Clone") +@Architecture.NoMemoryRequirements +public class AvrArchitecture implements Architecture { + private final Machine machine; + private AvrCore core; + private boolean debugRun; + private int delay; + private int[] tempData; + private int memSize; + + public AvrArchitecture(Machine machine) { + this.machine = machine; + } + + @Override + public boolean isInitialized() { + return core!=null && core.checkValid(); + } + + @Override + public boolean recomputeMemory(Iterable components) { + computeMemory(components); + return true; + } + + private void computeMemory(Iterable components) { + int memory = 0; + for (ItemStack component : components) { + Item driver = Driver.driverFor(component); + if (driver instanceof Memory) { + Memory memoryDriver = (Memory) driver; + memory += memoryDriver.amount(component) * 256;//in integers + }// else if (driver instanceof DriverEEPROM$) { + + //} + } + memory = Math.min(Math.max(memory, 0), Settings.get().maxTotalRam()); + if(memory!=memSize){ + + } + } + + @Override + public boolean initialize() { + core=new AvrCore(); + + computeMemory(this.machine.host().internalComponents()); + + if(isInitialized()) { + machine.beep("."); + return true; + } + return false; + } + + @Override + public void close() { + core=null; + tempData=null; + delay=0; + } + + @Override + public void runSynchronized() { + core.cycle(); + } + + @Override + public ExecutionResult runThreaded(boolean isSynchronizedReturn) { + if (core.awoken) { + delay=0; + for (int load=0; load < 512;) { + 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; + } + } + return null; + } + + @Override + public void onSignal() { + Signal signal=machine.popSignal(); + + core.interruptsHandle(); + } + + @Override + public void onConnect() { + //init network components, in case init was called from load logic (pre first tick?) + } + + @Override + public void load(NBTTagCompound avr) { + debugRun = avr.getBoolean("debugRun"); + delay = avr.getInteger("delay"); + core.active = avr.getBoolean("active"); + core.awoken = (avr.getBoolean("awoken")); + core.programCounter = avr.getInteger("programCounter"); + InstructionRegistry registry = + InstructionRegistry.REGISTRIES. + get(avr.getString("instructionRegistry")); + if (registry != null) { + byte[] instructions = SaveHandler.load(avr, this.machine.node().address() + "_instructionsMemory"); + byte[] param0 = SaveHandler.load(avr, this.machine.node().address() + "_param0Memory"); + byte[] param1 = SaveHandler.load(avr, this.machine.node().address() + "_param1Memory"); + if (instructions != null && param0 != null && param1 != null && + instructions.length > 0 && param0.length > 0 && param1.length > 0) { + int[] instr = null, par0 = null, par1 = null; + try { + GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(instructions)); + instr = Converter.readInts(IOUtils.toByteArray(gzis)); + IOUtils.closeQuietly(gzis); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to decompress instructions memory from disk."); + e.printStackTrace(); + } + try { + GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(param0)); + par0 = Converter.readInts(IOUtils.toByteArray(gzis)); + IOUtils.closeQuietly(gzis); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to decompress param0 memory from disk."); + e.printStackTrace(); + } + try { + GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(param1)); + par1 = Converter.readInts(IOUtils.toByteArray(gzis)); + IOUtils.closeQuietly(gzis); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to decompress param1 memory from disk."); + e.printStackTrace(); + } + if (instr != null && par0 != null && par1 != null && + instr.length==par0.length && instr.length==par1.length) { + core.setProgramMemory(new ProgramMemory( + registry, + avr.getBoolean("immersive"), + instr, + par0, + par1)); + } + } + } + if(avr.hasKey("eepromSize")){ + core.restoreEepromDefinition(EepromMemory.make(avr.getInteger("eepromSize"))); + } + byte[] data = SaveHandler.load(avr, this.machine.node().address() + "_dataMemory"); + if(data!=null && data.length > 0) { + try { + GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(data)); + tempData = Converter.readInts(IOUtils.toByteArray(gzis)); + IOUtils.closeQuietly(gzis); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to decompress data memory from disk."); + e.printStackTrace(); + } + } + core.checkValid(); + } + + @Override + public void save(NBTTagCompound avr) { + avr.setBoolean("debugRun",debugRun); + avr.setInteger("delay",delay); + avr.setBoolean("active",core.active); + avr.setBoolean("awoken",core.awoken); + avr.setInteger("programCounter",core.programCounter); + ProgramMemory programMemory=core.getProgramMemory(); + if(programMemory!=null){ + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzos = new GZIPOutputStream(baos); + gzos.write(Converter.writeInts(programMemory.instructions)); + gzos.close(); + SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_instructionsMemory", baos.toByteArray()); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to compress instructions memory to disk"); + e.printStackTrace(); + } + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzos = new GZIPOutputStream(baos); + gzos.write(Converter.writeInts(programMemory.param0)); + gzos.close(); + SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_param0Memory", baos.toByteArray()); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to compress param0 memory to disk"); + e.printStackTrace(); + } + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzos = new GZIPOutputStream(baos); + gzos.write(Converter.writeInts(programMemory.param1)); + gzos.close(); + SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_param1Memory", baos.toByteArray()); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to compress param1 memory to disk"); + e.printStackTrace(); + } + avr.setBoolean("immersive",programMemory.immersiveOperands); + avr.setString("instructionRegistry",programMemory.registry.toString()); + } + RemovableMemory eeprom=core.getEepromMemory(); + if(eeprom!=null){ + avr.setInteger("eepromSize",eeprom.getDefinition().getSize()); + } + if(core.dataMemory!=null) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzos = new GZIPOutputStream(baos); + gzos.write(Converter.writeInts(core.dataMemory)); + gzos.close(); + SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_dataMemory", baos.toByteArray()); + } catch (IOException e) { + TecTech.LOGGER.error("Failed to compress data memory to disk"); + e.printStackTrace(); + } + } + } +} 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 index 1d61d0744c..277c2de355 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java +++ b/src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java @@ -12,7 +12,6 @@ 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; @@ -32,9 +31,9 @@ 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 { + {@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 { public static AvrProgrammer INSTANCE=new AvrProgrammer(); private AvrProgrammer(){ -- cgit