-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Inventory Cable Connector not showing up in the creative inventory and JEI Added JEI compatibility to crafting terminal Fixed Storage Terminal recipe not using tags Terminals now emit light
- Loading branch information
Showing
15 changed files
with
325 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/com/tom/storagemod/jei/CraftingTerminalTransferHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.tom.storagemod.jei; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.inventory.container.Container; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.nbt.ListNBT; | ||
|
||
import com.google.common.base.Function; | ||
|
||
import com.tom.storagemod.gui.ContainerCraftingTerminal; | ||
|
||
import mezz.jei.api.constants.VanillaRecipeCategoryUid; | ||
import mezz.jei.api.gui.IRecipeLayout; | ||
import mezz.jei.api.gui.ingredient.IGuiIngredient; | ||
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; | ||
import mezz.jei.api.recipe.transfer.IRecipeTransferError; | ||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; | ||
import mezz.jei.api.registration.IRecipeTransferRegistration; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler { | ||
private final Class<? extends Container> containerClass; | ||
private static final List<Class<? extends Container>> containerClasses = new ArrayList<>(); | ||
private static final Function<IRecipeLayout, ItemStack[][]> transferFunc = new Function<IRecipeLayout, ItemStack[][]>() { | ||
@Override | ||
public ItemStack[][] apply(IRecipeLayout t) { | ||
List<ItemStack[]> inputs = new ArrayList<>(); | ||
IGuiItemStackGroup itemStackGroup = t.getItemStacks(); | ||
for (IGuiIngredient<ItemStack> ingredient : itemStackGroup.getGuiIngredients().values()) { | ||
if (ingredient.isInput()) { | ||
if (!ingredient.getAllIngredients().isEmpty() && ingredient.getAllIngredients().get(0) != null) { | ||
inputs.add(ingredient.getAllIngredients().toArray(new ItemStack[]{})); | ||
} else { | ||
inputs.add(null); | ||
} | ||
} | ||
} | ||
return inputs.toArray(new ItemStack[][]{}); | ||
} | ||
}; | ||
private static final IRecipeTransferError ERROR_INSTANCE = new IRecipeTransferError() { | ||
@Override public IRecipeTransferError.Type getType() { return IRecipeTransferError.Type.INTERNAL; } | ||
@Override public void showError(int mouseX, int mouseY, IRecipeLayout recipeLayout, int recipeX, int recipeY) {} | ||
}; | ||
static { | ||
containerClasses.add(ContainerCraftingTerminal.class); | ||
} | ||
|
||
public CraftingTerminalTransferHandler(Class<? extends Container> containerClass) { | ||
this.containerClass = containerClass; | ||
} | ||
|
||
@Override | ||
public Class<? extends Container> getContainerClass() { | ||
return containerClass; | ||
} | ||
|
||
@Override | ||
public IRecipeTransferError transferRecipe(Container container, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) { | ||
if (container instanceof IJEIAutoFillTerminal) { | ||
if (doTransfer) { | ||
ItemStack[][] stacks = transferFunc.apply(recipeLayout); | ||
CompoundNBT compound = new CompoundNBT(); | ||
ListNBT list = new ListNBT(); | ||
for (int i = 0;i < stacks.length;++i) { | ||
if (stacks[i] != null) { | ||
CompoundNBT CompoundNBT = new CompoundNBT(); | ||
CompoundNBT.putByte("s", (byte) i); | ||
for (int j = 0;j < stacks[i].length && j < 3;j++) { | ||
if (stacks[i][j] != null && !stacks[i][j].isEmpty()) { | ||
CompoundNBT tag = new CompoundNBT(); | ||
stacks[i][j].write(tag); | ||
CompoundNBT.put("i" + j, tag); | ||
} | ||
} | ||
CompoundNBT.putByte("l", (byte) Math.min(3, stacks[i].length)); | ||
list.add(CompoundNBT); | ||
} | ||
} | ||
compound.put("i", list); | ||
((IJEIAutoFillTerminal) container).sendMessage(compound); | ||
} | ||
} else { | ||
return ERROR_INSTANCE; | ||
} | ||
return null; | ||
} | ||
|
||
public static void registerTransferHandlers(IRecipeTransferRegistration recipeTransferRegistry) { | ||
for (int i = 0;i < containerClasses.size();i++) | ||
recipeTransferRegistry.addRecipeTransferHandler(new CraftingTerminalTransferHandler(containerClasses.get(i)), VanillaRecipeCategoryUid.CRAFTING); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/tom/storagemod/jei/IJEIAutoFillTerminal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.tom.storagemod.jei; | ||
|
||
import net.minecraft.nbt.CompoundNBT; | ||
|
||
public interface IJEIAutoFillTerminal { | ||
void sendMessage(CompoundNBT compound); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.tom.storagemod.jei; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import com.tom.storagemod.StorageMod; | ||
import com.tom.storagemod.gui.GuiCraftingTerminal; | ||
|
||
import mezz.jei.api.IModPlugin; | ||
import mezz.jei.api.JeiPlugin; | ||
import mezz.jei.api.constants.VanillaRecipeCategoryUid; | ||
import mezz.jei.api.registration.IGuiHandlerRegistration; | ||
import mezz.jei.api.registration.IRecipeCatalystRegistration; | ||
import mezz.jei.api.registration.IRecipeTransferRegistration; | ||
|
||
@JeiPlugin | ||
public class JEIHandler implements IModPlugin { | ||
|
||
@Override | ||
public ResourceLocation getPluginUid() { | ||
return new ResourceLocation(StorageMod.modid, "jei"); | ||
} | ||
|
||
@Override | ||
public void registerGuiHandlers(IGuiHandlerRegistration registration) { | ||
registration.addRecipeClickArea(GuiCraftingTerminal.class, 83, 125, 28, 23, new ResourceLocation[] { VanillaRecipeCategoryUid.CRAFTING }); | ||
} | ||
|
||
@Override | ||
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { | ||
CraftingTerminalTransferHandler.registerTransferHandlers(registration); | ||
} | ||
|
||
@Override | ||
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { | ||
registration.addRecipeCatalyst(new ItemStack(StorageMod.craftingTerminal), new ResourceLocation[] { VanillaRecipeCategoryUid.CRAFTING }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.tom.storagemod.network; | ||
|
||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.network.PacketBuffer; | ||
|
||
public class DataPacket { | ||
public CompoundNBT tag; | ||
|
||
public DataPacket(CompoundNBT tag) { | ||
this.tag = tag; | ||
} | ||
|
||
public DataPacket(PacketBuffer pb) { | ||
tag = pb.readCompoundTag(); | ||
} | ||
|
||
public void toBytes(PacketBuffer pb) { | ||
pb.writeCompoundTag(tag); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tom.storagemod.network; | ||
|
||
import net.minecraft.nbt.CompoundNBT; | ||
|
||
public interface IDataReceiver { | ||
void receive(CompoundNBT tag); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/tom/storagemod/network/NetworkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.tom.storagemod.network; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import net.minecraftforge.fml.network.NetworkDirection; | ||
import net.minecraftforge.fml.network.NetworkEvent; | ||
import net.minecraftforge.fml.network.NetworkRegistry; | ||
import net.minecraftforge.fml.network.PacketDistributor; | ||
import net.minecraftforge.fml.network.simple.SimpleChannel; | ||
|
||
import com.tom.storagemod.StorageMod; | ||
|
||
public class NetworkHandler { | ||
private static final String PROTOCOL_VERSION = "1"; | ||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( | ||
new ResourceLocation(StorageMod.modid, "main"), | ||
() -> PROTOCOL_VERSION, | ||
PROTOCOL_VERSION::equals, | ||
PROTOCOL_VERSION::equals | ||
); | ||
public static void init() { | ||
INSTANCE.registerMessage(0, DataPacket.class, DataPacket::toBytes, DataPacket::new, NetworkHandler::handleData); | ||
StorageMod.LOGGER.info("Initilaized Network Handler"); | ||
} | ||
|
||
public static void handleData(DataPacket packet, Supplier<NetworkEvent.Context> ctx) { | ||
if(ctx.get().getDirection() == NetworkDirection.PLAY_TO_SERVER) { | ||
ctx.get().enqueueWork(() -> { | ||
ServerPlayerEntity sender = ctx.get().getSender(); | ||
if(sender.openContainer instanceof IDataReceiver) { | ||
((IDataReceiver)sender.openContainer).receive(packet.tag); | ||
} | ||
}); | ||
} else if(ctx.get().getDirection() == NetworkDirection.PLAY_TO_CLIENT) { | ||
ctx.get().enqueueWork(() -> { | ||
if(Minecraft.getInstance().currentScreen instanceof IDataReceiver) { | ||
((IDataReceiver)Minecraft.getInstance().currentScreen).receive(packet.tag); | ||
} | ||
}); | ||
} | ||
ctx.get().setPacketHandled(true); | ||
} | ||
|
||
public static void sendDataToServer(CompoundNBT tag) { | ||
INSTANCE.sendToServer(new DataPacket(tag)); | ||
} | ||
|
||
public static void sendTo(ServerPlayerEntity pl, CompoundNBT tag) { | ||
INSTANCE.send(PacketDistributor.PLAYER.with(() -> pl), new DataPacket(tag)); | ||
} | ||
} |
Oops, something went wrong.