More auto crafting table stuff

This commit is contained in:
modmuss50 2017-06-20 21:31:21 +01:00
parent 3071d19db0
commit a7316bc6c0
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
6 changed files with 148 additions and 2 deletions

View file

@ -57,6 +57,7 @@ import techreborn.init.*;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketAesu;
import techreborn.packets.PacketIdsu;
import techreborn.packets.PacketSetRecipe;
import techreborn.packets.PacketSyncSideConfig;
import techreborn.proxies.CommonProxy;
import techreborn.utils.StackWIPHandler;
@ -199,6 +200,7 @@ public class Core {
event.registerPacket(PacketSyncSideConfig.class, Side.SERVER);
event.registerPacket(PacketAesu.class, Side.SERVER);
event.registerPacket(PacketIdsu.class, Side.SERVER);
event.registerPacket(PacketSetRecipe.class, Side.SERVER);
}
@Mod.EventHandler

View file

@ -1,17 +1,26 @@
package techreborn.client.gui.autocrafting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButtonImage;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import org.lwjgl.opengl.GL11;
import reborncore.common.network.NetworkManager;
import techreborn.client.gui.GuiBase;
import techreborn.packets.PacketSetRecipe;
import techreborn.tiles.TileAutoCraftingTable;
import java.io.IOException;
import static net.minecraft.item.ItemStack.EMPTY;
/**
* Created by modmuss50 on 20/06/2017.
*/
@ -21,9 +30,11 @@ public class GuiAutoCrafting extends GuiBase {
private GuiButtonImage recipeButton;
boolean showGui = true;
InventoryCrafting dummyInv;
TileAutoCraftingTable tileAutoCraftingTable;
public GuiAutoCrafting(EntityPlayer player, TileAutoCraftingTable tile) {
super(player, tile, tile.createContainer(player));
this.tileAutoCraftingTable = tile;
}
@Override
@ -32,9 +43,32 @@ public class GuiAutoCrafting extends GuiBase {
recipeSlector.func_193957_d();
}
public void renderItemStack(ItemStack stack, int x, int y) {
if (stack != EMPTY) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderHelper.enableGUIStandardItemLighting();
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
itemRenderer.renderItemAndEffectIntoGUI(stack, x, y);
GL11.glDisable(GL11.GL_LIGHTING);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
IRecipe recipe = tileAutoCraftingTable.getIRecipe();
if(recipe != null){
renderItemStack(recipe.getRecipeOutput(), 10, 25);
}
}
@Override
public void initGui() {
super.initGui();
recipeSlector.setGuiAutoCrafting(this);
dummyInv = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
@ -51,7 +85,7 @@ public class GuiAutoCrafting extends GuiBase {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (showGui) {
this.recipeSlector.func_191861_a(mouseX, mouseY, partialTicks);
this.recipeSlector.func_191861_a(mouseX, mouseY, 0.1F);
super.drawScreen(mouseX, mouseY, partialTicks);
this.recipeSlector.func_191864_a(this.guiLeft, this.guiTop, false, partialTicks);
} else {
@ -87,4 +121,10 @@ public class GuiAutoCrafting extends GuiBase {
super.onGuiClosed();
}
public void setRecipe(IRecipe recipe){
tileAutoCraftingTable.setCurrentRecipe(recipe.getRegistryName());
NetworkManager.sendToServer(new PacketSetRecipe(tileAutoCraftingTable, recipe.getRegistryName()));
}
}

View file

@ -1,7 +1,11 @@
package techreborn.client.gui.autocrafting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButtonToggle;
import net.minecraft.client.gui.recipebook.GuiRecipeBook;
import net.minecraft.client.gui.recipebook.RecipeList;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.crafting.IRecipe;
/**
@ -9,8 +13,29 @@ import net.minecraft.item.crafting.IRecipe;
*/
public class GuiAutoCraftingRecipeSlector extends GuiRecipeBook {
GuiAutoCrafting guiAutoCrafting;
@Override
public void func_193014_a(boolean p_193014_1_, InventoryCrafting p_193014_2_) {
super.func_193014_a(p_193014_1_, p_193014_2_);
//Pulls the button off the screen as we dont need it
field_193960_m = new GuiButtonToggle(0, -1000, -1000, 26, 16, false);
field_193960_m.func_191751_a(152, 41, 28, 18, RECIPE_BOOK);
}
@Override
public void func_191856_a(int p_191856_1_, int p_191856_2_, Minecraft mc, boolean p_191856_4_, Container p_191856_5_, InventoryCrafting p_191856_6_) {
super.func_191856_a(p_191856_1_, p_191856_2_, mc, p_191856_4_, p_191856_5_, p_191856_6_);
}
@Override
public void func_193945_a(IRecipe recipe, RecipeList recipes) {
System.out.println(recipe.getRecipeOutput().getDisplayName());
guiAutoCrafting.setRecipe(recipe);
}
public void setGuiAutoCrafting(GuiAutoCrafting guiAutoCrafting) {
this.guiAutoCrafting = guiAutoCrafting;
}
}

View file

@ -0,0 +1,52 @@
package techreborn.packets;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import reborncore.common.network.ExtendedPacketBuffer;
import reborncore.common.network.INetworkPacket;
import techreborn.tiles.TileAutoCraftingTable;
import java.io.IOException;
/**
* Created by modmuss50 on 20/06/2017.
*/
public class PacketSetRecipe implements INetworkPacket<PacketSetRecipe> {
BlockPos pos;
ResourceLocation recipe;
public PacketSetRecipe(TileAutoCraftingTable tile, ResourceLocation recipe) {
this.pos = tile.getPos();
this.recipe = recipe;
if(this.recipe == null){
//TODO fix vanilla recipes
this.recipe = new ResourceLocation("");
}
}
public PacketSetRecipe() {
}
@Override
public void writeData(ExtendedPacketBuffer buffer) throws IOException {
buffer.writeBlockPos(pos);
buffer.writeResourceLocation(recipe);
}
@Override
public void readData(ExtendedPacketBuffer buffer) throws IOException {
pos = buffer.readBlockPos();
recipe = buffer.readResourceLocation();
}
@Override
public void processData(PacketSetRecipe message, MessageContext context) {
TileEntity tileEntity = context.getServerHandler().player.world.getTileEntity(pos);;
if(tileEntity instanceof TileAutoCraftingTable){
((TileAutoCraftingTable) tileEntity).setCurrentRecipe(recipe);
}
}
}

View file

@ -1,16 +1,36 @@
package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import javax.annotation.Nullable;
/**
* Created by modmuss50 on 20/06/2017.
*/
public class TileAutoCraftingTable extends TilePowerAcceptor implements IContainerProvider {
ResourceLocation currentRecipe;
public void setCurrentRecipe(ResourceLocation recipe){
currentRecipe = recipe;
}
@Nullable
public IRecipe getIRecipe(){
if(currentRecipe == null){
return null;
}
return ForgeRegistries.RECIPES.getValue(currentRecipe);
}
public TileAutoCraftingTable() {
super();
}
@ -44,4 +64,9 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
public BuiltContainer createContainer(EntityPlayer player) {
return new ContainerBuilder("autocraftingTable").player(player.inventory).inventory().hotbar().addInventory().create();
}
@Override
public boolean canBeUpgraded() {
return false;
}
}

View file

@ -1 +1,3 @@
public net.minecraft.client.gui.recipebook.GuiRecipeBook func_193945_a(Lnet/minecraft/item/crafting/IRecipe;Lnet/minecraft/client/gui/recipebook/RecipeList;)V # func_193945_a
public net.minecraft.client.gui.recipebook.GuiRecipeBook field_193960_m # toggleRecipesBtn