Add config option for the inventory type.

main
Astoria 1 year ago
parent a6d0afa9cf
commit a335674b36

@ -31,10 +31,10 @@ public class IronChestMain implements ModInitializer {
LOGGER.info("AFloydIronChest initialized."); LOGGER.info("AFloydIronChest initialized.");
//Config //Config
Toml toml = new Toml().read(this.getConfig()); Toml toml = new Toml().read(this.getConfig());
int ironChestId = toml.getLong("ids.ironChestID").intValue(); int ironChestId = toml.getLong("ids.ironChestID", (long)800).intValue();
int goldChestId = toml.getLong("ids.goldChestID").intValue(); int goldChestId = toml.getLong("ids.goldChestID", (long)801).intValue();
int diamondChestId = toml.getLong("ids.diamondChestID").intValue(); int diamondChestId = toml.getLong("ids.diamondChestID", (long)802).intValue();
int steelChestId = toml.getLong("ids.steelChestID").intValue(); int steelChestId = toml.getLong("ids.steelChestID", (long)803).intValue();
//Blocks //Blocks
@ -95,14 +95,14 @@ public class IronChestMain implements ModInitializer {
}); });
} }
public File getConfig() { public static File getConfig() {
File config = new File("config/AstoriaIronChest.toml"); File config = new File("config/AstoriaIronChest.toml");
if (!config.exists()) { if (!config.exists()) {
LOGGER.warn("Config For afloydironchest Not Found! Creating new config based upon default :)"); LOGGER.warn("Config For afloydironchest Not Found! Creating new config based upon default :)");
InputStream in; InputStream in;
OutputStream out; OutputStream out;
try { try {
in = getClass().getClassLoader().getResourceAsStream("assets/ironchest/config.toml"); in = IronChestMain.class.getClassLoader().getResourceAsStream("assets/ironchest/config.toml");
out = new FileOutputStream(config); out = new FileOutputStream(config);
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int length; int length;

@ -1,5 +1,7 @@
package net.brokenmoon.afloydironchest.mixin; package net.brokenmoon.afloydironchest.mixin;
import com.moandjiezana.toml.Toml;
import net.brokenmoon.afloydironchest.IronChestMain;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP; import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP;
import net.brokenmoon.afloydironchest.gui.ContainerWideChest; import net.brokenmoon.afloydironchest.gui.ContainerWideChest;
import net.minecraft.src.*; import net.minecraft.src.*;
@ -17,6 +19,8 @@ public class MixinEntityPlayerMP implements IEntityPlayerMP {
@Shadow @Shadow
public NetServerHandler playerNetServerHandler; public NetServerHandler playerNetServerHandler;
public int ironchest_windowid = 0;
public void displayGUIIronChest(IInventory iinventory) { public void displayGUIIronChest(IInventory iinventory) {
this.getNextWindowId(); this.getNextWindowId();
NetServerHandler.logger.info(((EntityPlayerMP)(Object)this).username + " interacted with chest at (" + ((EntityPlayerMP)(Object)this).posX + ", " + ((EntityPlayerMP)(Object)this).posY + ", " + ((EntityPlayerMP)(Object)this).posZ + ")"); NetServerHandler.logger.info(((EntityPlayerMP)(Object)this).username + " interacted with chest at (" + ((EntityPlayerMP)(Object)this).posX + ", " + ((EntityPlayerMP)(Object)this).posY + ", " + ((EntityPlayerMP)(Object)this).posZ + ")");
@ -29,9 +33,19 @@ public class MixinEntityPlayerMP implements IEntityPlayerMP {
public void displayGUIDiamondChest(IInventory iinventory) { public void displayGUIDiamondChest(IInventory iinventory) {
this.getNextWindowId(); this.getNextWindowId();
NetServerHandler.logger.info(((EntityPlayerMP)(Object)this).username + " interacted with chest at (" + ((EntityPlayerMP)(Object)this).posX + ", " + ((EntityPlayerMP)(Object)this).posY + ", " + ((EntityPlayerMP)(Object)this).posZ + ")"); NetServerHandler.logger.info(((EntityPlayerMP)(Object)this).username + " interacted with chest at (" + ((EntityPlayerMP)(Object)this).posX + ", " + ((EntityPlayerMP)(Object)this).posY + ", " + ((EntityPlayerMP)(Object)this).posZ + ")");
this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, 7, iinventory.getInvName(), iinventory.getSizeInventory())); this.playerNetServerHandler.sendPacket(new Packet100OpenWindow(this.currentWindowId, getIronchest_windowid(), iinventory.getInvName(), iinventory.getSizeInventory()));
((EntityPlayerMP)(Object)this).craftingInventory = new ContainerWideChest(((EntityPlayerMP)(Object)this).inventory, iinventory); ((EntityPlayerMP)(Object)this).craftingInventory = new ContainerWideChest(((EntityPlayerMP)(Object)this).inventory, iinventory);
((EntityPlayerMP)(Object)this).craftingInventory.windowId = this.currentWindowId; ((EntityPlayerMP)(Object)this).craftingInventory.windowId = this.currentWindowId;
((EntityPlayerMP)(Object)this).craftingInventory.onContainerInit(((EntityPlayerMP)(Object)this)); ((EntityPlayerMP)(Object)this).craftingInventory.onContainerInit(((EntityPlayerMP)(Object)this));
} }
public int getIronchest_windowid(){
if (ironchest_windowid != 0 ){
return ironchest_windowid;
} else{
Toml toml = new Toml().read(IronChestMain.getConfig());
ironchest_windowid = toml.getLong("ids.diamondWindowID", (long)7).intValue();
return getIronchest_windowid();
}
}
} }

@ -1,5 +1,7 @@
package net.brokenmoon.afloydironchest.mixin; package net.brokenmoon.afloydironchest.mixin;
import com.moandjiezana.toml.Toml;
import net.brokenmoon.afloydironchest.IronChestMain;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP; import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityDiamondChest; import net.brokenmoon.afloydironchest.tileEntities.TileEntityDiamondChest;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -14,16 +16,28 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = NetClientHandler.class, remap = false) @Mixin(value = NetClientHandler.class, remap = false)
public class MixinNetClientHandler { public class MixinNetClientHandler {
private int ironchest_windowid = 0;
@Shadow @Shadow
private Minecraft mc; private Minecraft mc;
@Inject(method = "handleOpenWindow", at = @At("TAIL")) @Inject(method = "handleOpenWindow", at = @At("TAIL"))
public void injectMethod(Packet100OpenWindow packet100openwindow, CallbackInfo info) { public void injectMethod(Packet100OpenWindow packet100openwindow, CallbackInfo info) {
if (packet100openwindow.inventoryType == 7) { if (packet100openwindow.inventoryType == getIronchest_windowid()) {
TileEntityDiamondChest dchest = new TileEntityDiamondChest(); TileEntityDiamondChest dchest = new TileEntityDiamondChest();
((IEntityPlayerSP)this.mc.thePlayer).displayGUIDiamondChest(dchest); ((IEntityPlayerSP)this.mc.thePlayer).displayGUIDiamondChest(dchest);
this.mc.thePlayer.craftingInventory.windowId = packet100openwindow.windowId; this.mc.thePlayer.craftingInventory.windowId = packet100openwindow.windowId;
} }
} }
public int getIronchest_windowid(){
if (ironchest_windowid != 0 ){
return ironchest_windowid;
} else{
Toml toml = new Toml().read(IronChestMain.getConfig());
ironchest_windowid = toml.getLong("ids.diamondWindowID", (long)7).intValue();
return getIronchest_windowid();
}
}
} }

@ -2,4 +2,5 @@
ironChestID = 900 ironChestID = 900
goldChestID = 901 goldChestID = 901
diamondChestID = 902 diamondChestID = 902
steelChestID = 903 steelChestID = 903
diamondWindowID = 7
Loading…
Cancel
Save