Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Feb 6, 2024
1 parent fd993c8 commit b9b360b
Show file tree
Hide file tree
Showing 19 changed files with 1,013 additions and 202 deletions.
421 changes: 254 additions & 167 deletions src/main/java/reobf/proghatches/block/TileIOHub.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
Expand All @@ -45,6 +46,7 @@
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder;
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
Expand All @@ -58,10 +60,13 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.enums.SoundResource;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.IMachineProgress;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus;
import gregtech.api.util.GT_TooltipDataCache.TooltipData;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.extensions.ArrayExt;
Expand Down Expand Up @@ -608,16 +613,18 @@ public static class CallerCheck {
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.getWorld().isRemote) return;

if(this.getBaseMetaTileEntity().isAllowedToWork())
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (inv0.full() == false) {
inv0.recordRecipeOrCalssify(this.mStoredFluid, mInventory);
inv0.classify(this.mStoredFluid, mInventory);
}
}

// BaseMetaTileEntity h;
// h.add4by4Slots(builder, background);

}
}

@Override
public ItemStack getStackInSlot(int aIndex) {
Expand Down Expand Up @@ -814,7 +821,7 @@ private Widget createButtonBuffer(int id) {

protected ModularWindow createWindow(final EntityPlayer player, int index) {
DualInvBuffer inv0 = this.inv0.get(index);
final int WIDTH = 18 * 6 + 6;
final int WIDTH = 18 * 6 + 6;
final int HEIGHT = 18 * 4 + 6;
final int PARENT_WIDTH = getGUIWidth();
final int PARENT_HEIGHT = getGUIHeight();
Expand Down Expand Up @@ -956,7 +963,37 @@ private NBTTagCompound cv(String s) {
return new NBTTagCompound();
}
}

ButtonWidget createPowerSwitchButton(IWidgetBuilder<?> builder) {IGregTechTileEntity thiz=this.getBaseMetaTileEntity();
Widget button = new ButtonWidget().setOnClick((clickData, widget) -> {

if (thiz.isAllowedToWork()) {
thiz.disableWorking();
} else {
thiz.enableWorking();
}
})
.setPlayClickSoundResource( () -> thiz.isAllowedToWork() ? SoundResource.GUI_BUTTON_UP.resourceLocation
: SoundResource.GUI_BUTTON_DOWN.resourceLocation
)
.setBackground(() -> {
if (thiz.isAllowedToWork()) {
return new IDrawable[] { GT_UITextures.BUTTON_STANDARD_PRESSED,
GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_ON };
} else {
return new IDrawable[] { GT_UITextures.BUTTON_STANDARD,
GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF };
}
})
.attachSyncer(new FakeSyncWidget.BooleanSyncer(thiz::isAllowedToWork, val -> {
if (val) thiz.enableWorking();
else thiz.disableWorking();
}), builder)
.addTooltip(StatCollector.translateToLocal("GT5U.gui.button.power_switch"))
.setTooltipShowUpDelay(TOOLTIP_DELAY)
.setPos(new Pos2d(getGUIWidth()-18-6,3))
.setSize(16, 16);
return (ButtonWidget) button;
}
@Override
public void addUIWidgets(Builder builder, UIBuildContext buildContext) {

Expand All @@ -966,6 +1003,9 @@ public void addUIWidgets(Builder builder, UIBuildContext buildContext) {

builder.widget(createButtonBuffer(i));
}

builder.widget(createPowerSwitchButton(builder));

super.addUIWidgets(builder, buildContext);
// builder.widget(widget);

Expand Down
26 changes: 20 additions & 6 deletions src/main/java/reobf/proghatches/main/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.google.common.base.Optional;

import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.util.GT_ModHandler;
import mcp.mobius.waila.api.IWailaRegistrar;
import reobf.proghatches.Tags;
import reobf.proghatches.block.BlockIOHub;
import reobf.proghatches.block.ItemBlockIOHub;
Expand All @@ -27,6 +29,8 @@
import reobf.proghatches.main.registration.Registration;
import reobf.proghatches.oc.ItemAPICard;
import reobf.proghatches.oc.ItemGTRedstoneCard;
import reobf.proghatches.oc.ItemWirelessPeripheralCard;
import reobf.proghatches.oc.TileWirelessPeripheralStation;

public class CommonProxy {

Expand All @@ -40,7 +44,7 @@ public void preInit(FMLPreInitializationEvent event) {
MyMod.LOG.info("I am " + Tags.MODNAME + " at version " + Tags.VERSION);

GameRegistry.registerTileEntity(TileIOHub.class, "proghatches.iohub");

GameRegistry.registerTileEntity(TileWirelessPeripheralStation.class, "proghatches.peripheral_station");
GameRegistry.registerItem(
MyMod.progcircuit = new ItemProgrammingCircuit().setUnlocalizedName("prog_circuit")
.setTextureName("?"),
Expand Down Expand Up @@ -71,15 +75,22 @@ public void preInit(FMLPreInitializationEvent event) {
.setUnlocalizedName("proghatches.oc.api")
.setTextureName("proghatches:APIcard"),
"proghatches.oc.api");

GameRegistry.registerItem(
MyMod.pitem = new ItemWirelessPeripheralCard().setMaxStackSize(1)
.setUnlocalizedName("proghatches.oc.peripheral_card")
.setTextureName("proghatches:peripheral_card"),
"proghatches.oc.peripheral_card");
MyMod.iohub =GameRegistry.registerBlock(
new BlockIOHub(),ItemBlockIOHub.class,"proghatches.iohub");

MyMod.pstation =GameRegistry.registerBlock(
new TileWirelessPeripheralStation.Block(),TileWirelessPeripheralStation.ItemBlock.class,"proghatches.peripheral_station");

li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Item) MyMod.oc_redstone);
li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Item) MyMod.oc_api);
// li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Block)MyMod.iohub);
li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Item) MyMod.pitem);
GT_ModHandler.addToRecyclerBlackList(new ItemStack(MyMod.progcircuit));
FMLInterModComms.sendMessage("Waila", "register", "reobf.proghatches.main.CommonProxy.callbackRegister");

}

public static ProgHatchCreativeTab tab;
Expand All @@ -95,9 +106,12 @@ public void init(FMLInitializationEvent event) {
public void postInit(FMLPostInitializationEvent event) {

new PHRecipes().run();


}
public static void callbackRegister(IWailaRegistrar registrar) {
registrar.registerBodyProvider(TileWirelessPeripheralStation.provider, MyMod.pstation.getClass());
registrar.registerNBTProvider(TileWirelessPeripheralStation.provider, MyMod.pstation.getClass());
}

// register server commands in this event handler (Remove if not needed)
public void serverStarting(FMLServerStartingEvent event) {}
}
9 changes: 6 additions & 3 deletions src/main/java/reobf/proghatches/main/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ public class Config {

public static String greeting = "Hello World";
public static int metaTileEntityOffset = 22000;

public static boolean skipRecipeAdding;
public static void synchronizeConfiguration(File configFile) {
Configuration configuration = new Configuration(configFile);

greeting = configuration.getString("greeting", Configuration.CATEGORY_GENERAL, greeting, "How shall I greet?");

// greeting = configuration.getString("greeting", Configuration.CATEGORY_GENERAL, greeting, "How shall I greet?");
metaTileEntityOffset= configuration.getInt("MetaTEOffset", "ID", metaTileEntityOffset, 14301, 29999, "The GT MetaTE ID used by this mod, will use range:[offset,offset+200], make sure it's in [14301,14999] or [17000,29999]");
configuration.addCustomCategoryComment("ID", "Configurable ID settings, DO NOT change it until necessary.");
skipRecipeAdding= configuration.getBoolean("skipRecipeAddition", Configuration.CATEGORY_GENERAL, skipRecipeAdding, "If true, this mod will not add any recipe.");

if (configuration.hasChanged()) {
configuration.save();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/reobf/proghatches/main/MyMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import reobf.proghatches.Tags;
import reobf.proghatches.block.TileIOHub.OCApi;
import reobf.proghatches.oc.WirelessPeripheralManager;
import reobf.proghatches.util.ProghatchesUtil;

@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]"
Expand All @@ -45,6 +46,8 @@ public class MyMod {
public static Item oc_redstone;
public static Item oc_api;
public static Block iohub;
public static Block pstation;
public static Item pitem;

@Mod.EventHandler
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
Expand Down Expand Up @@ -92,6 +95,8 @@ public void postInit(FMLPostInitializationEvent event) {
// register server commands in this event handler (Remove if not needed)
public void serverStarting(FMLServerStartingEvent event) {
proxy.serverStarting(event);
WirelessPeripheralManager.stations.clear();
WirelessPeripheralManager.cards.clear();
}

public static ItemStack tutorial() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ private List g(List<PositionedStack> c) {
* Iterator ii, PositionedStack iii){
* }
* 牛的 mixin还能混出VerifyError
* 真想直接上coremod了
* 我不用localcapture还不行吗
* cpw.mods.fml.common.LoaderException: java.lang.VerifyError: Bad local variable type
* Exception Details:
* Location:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class PHRecipes implements Runnable {
public void run() {



if(Config.skipRecipeAdding)return;
ArrayList<ItemStack> pc0 = new ArrayList<>();
HashMap<ItemStack, Integer/* item->productivity */> pc = new HashMap<>();// List<Pair<ItemStack,Integer>>

Expand Down
48 changes: 36 additions & 12 deletions src/main/java/reobf/proghatches/oc/ItemAPICard.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package reobf.proghatches.oc;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.oredict.OreDictionary;
Expand Down Expand Up @@ -87,8 +92,27 @@ public Node node() {
return _node;

}
@Callback(doc = "getID(tag:string):table --parse binary deflated NBT tag as readable table", direct = false)
public Object[] getTag(final Context context, final Arguments args) {

try {


return new Object[] { CompressedStreamTools.readCompressed(new ByteArrayInputStream(
//args.checkString(0)).getBytes() will truncate byte to 0~127
//have no idea why that happens
(byte[]) args.checkAny(0))
)
};
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("format error");
}

//return new Object[] { };

@Callback(doc = "getID(database:address,index:number) --get item ID in number", direct = false)
}
@Callback(doc = "getID(database:address,index:number):string --get item ID in number", direct = false)
public Object[] getID(final Context context, final Arguments args) {
Node n = node().network()
.node(args.checkString(0));
Expand All @@ -106,7 +130,7 @@ public Object[] getID(final Context context, final Arguments args) {
// database.GET
}

@Callback(doc = "getOreDict(database:address,index:number) --get OreDicts", direct = false)
@Callback(doc = "getOreDict(database:address,index:number):string --get OreDicts", direct = false)
public Object[] getOreDict(final Context context, final Arguments args) {
Node n = node().network()
.node(args.checkString(0));
Expand Down Expand Up @@ -135,7 +159,7 @@ public Object[] getOreDict(final Context context, final Arguments args) {
}

@Callback(
doc = "match(database:address,index:number,regex:string[,mode:string]) --check with regex to see if target has OreDict, 'mode' can be 'find'(default) or 'match'",
doc = "match(database:address,index:number,regex:string[,mode:string]):boolean --check with regex to see if target has OreDict, 'mode' can be 'find'(default) or 'match'",
direct = false)
public Object[] match(final Context context, final Arguments args) {
Node n = node().network()
Expand Down Expand Up @@ -176,13 +200,13 @@ public Object[] match(final Context context, final Arguments args) {
// database.GET
}

@Callback(doc = "nameToID(name:string) --string ID -> number ID", direct = false)
@Callback(doc = "nameToID(name:string):int --string ID -> number ID", direct = false)
public Object[] nameToID(final Context context, final Arguments args) {

return new Object[] { Item.getIdFromItem((Item) itemRegistry.getObject(args.checkString(0))) };
}

@Callback(doc = "idToName(id:number) --number ID -> string ID", direct = false)
@Callback(doc = "idToName(id:number):string --number ID -> string ID", direct = false)
public Object[] idToName(final Context context, final Arguments args) {

return new Object[] { itemRegistry.getNameForObject(Item.getItemById(args.checkInteger(0))) };
Expand All @@ -197,30 +221,30 @@ public void onConnect(Node node) {
@Override
public void onDisconnect(Node node) {

// System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");

}

@Override
public void onMessage(Message message) {
// TODO Auto-generated method stub


}

@Override
public void load(NBTTagCompound nbt) {
// TODO Auto-generated method stub
Optional.ofNullable(nbt.getTag("node")).ifPresent(s->{if(node()!=null)node().load((NBTTagCompound) s);});

}

@Override
public void save(NBTTagCompound nbt) {
// TODO Auto-generated method stub

NBTTagCompound t=new NBTTagCompound();
Optional.ofNullable(node()).ifPresent(s->s.save(t));
nbt.setTag("node", t);
}

@Override
public boolean canUpdate() {
// TODO Auto-generated method stub

return false;
}

Expand Down
Loading

0 comments on commit b9b360b

Please sign in to comment.