Skip to content

Commit

Permalink
1.11.2 (beta) Inventory changes are plentiful.
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Feb 21, 2017
1 parent a78b58f commit 1129d1a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 55 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -25,9 +25,9 @@ group = "net.doubledoordev.mtrm"
archivesBaseName = "MineTweakerRecipeMaker"

minecraft {
version = "1.10.2-12.18.2.2099"
version = "1.11.2-13.20.0.2235"
runDir = "run"
mappings = "snapshot_20161013"
mappings = "snapshot_20170221"
}

processResources {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/doubledoordev/mtrm/MTRMCommand.java
Expand Up @@ -14,13 +14,13 @@
public class MTRMCommand extends CommandBase
{
@Override
public String getCommandName()
public String getName()
{
return "minetweakerrecipemaker";
}

@Override
public List<String> getCommandAliases()
public List<String> getAliases()
{
return Arrays.asList("mtrm");
}
Expand All @@ -32,7 +32,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_)
public String getUsage(ICommandSender p_71518_1_)
{
return "Step 4: PROFIT?";
}
Expand Down
Expand Up @@ -6,14 +6,11 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Logger;

import java.util.Map;

/**
* @author Dries007
*/
Expand Down
42 changes: 19 additions & 23 deletions src/main/java/net/doubledoordev/mtrm/gui/MTRMContainer.java
Expand Up @@ -5,8 +5,6 @@
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;

import javax.annotation.Nullable;

/**
* @author Dries007
*/
Expand Down Expand Up @@ -50,33 +48,32 @@ protected void retrySlotClick(int p_75133_1_, int p_75133_2_, boolean p_75133_3_

}

@Nullable
@Override
public ItemStack slotClick(int i, int mousebtn, ClickType clickTypeIn, EntityPlayer player)
{
ItemStack stack = null;
ItemStack stack = ItemStack.EMPTY;
if ((i >= 0 && i <= 9) || i == RETURN_SLOT_ID) // Fake slots
{
if (mousebtn == 2)
{
getSlot(i).putStack(null);
getSlot(i).putStack(ItemStack.EMPTY);
}
else if (mousebtn == 0)
{
InventoryPlayer playerInv = player.inventory;
getSlot(i).onSlotChanged();
// getSlot(i).onSlotChanged();
ItemStack stackSlot = getSlot(i).getStack();
ItemStack stackHeld = playerInv.getItemStack();

if (stackSlot != null) stack = stackSlot.copy();
if (!stackSlot.isEmpty()) stack = stackSlot.copy();

if (stackHeld != null)
if (!stackHeld.isEmpty())
{
ItemStack newStack = stackHeld.copy();
if (!(i == 0 || i == RETURN_SLOT_ID)) newStack.stackSize = 1;
if (!(i == 0 || i == RETURN_SLOT_ID)) newStack.setCount(1);
getSlot(i).putStack(newStack);
}
else getSlot(i).putStack(null);
else getSlot(i).putStack(ItemStack.EMPTY);
}
else if (mousebtn == 1)
{
Expand All @@ -85,29 +82,27 @@ else if (mousebtn == 1)
ItemStack stackSlot = getSlot(i).getStack();
ItemStack stackHeld = playerInv.getItemStack();

if (stackSlot != null) stack = stackSlot.copy();
stack = stackSlot.copy();

if (stackHeld != null)
if (!stackHeld.isEmpty())
{
stackHeld = stackHeld.copy();
if (stackSlot != null && stackHeld.isItemEqual(stackSlot) && (i == 0 || i == RETURN_SLOT_ID))
if (!stackSlot.isEmpty() && stackHeld.isItemEqual(stackSlot) && (i == 0 || i == RETURN_SLOT_ID))
{
int max = stackSlot.getMaxStackSize();
if (++stackSlot.stackSize > max) stackSlot.stackSize = max;
getSlot(i).putStack(stackSlot);
if (stackSlot.getCount() < stackSlot.getMaxStackSize()) stackSlot.grow(1);
}
else
{
stackHeld.stackSize = 1;
getSlot(i).putStack(stackHeld);
stackSlot.setCount(1);
}
getSlot(i).putStack(stackSlot);
}
else
{
if (stackSlot != null)
if (!stackSlot.isEmpty())
{
stackSlot.stackSize--;
if (stackSlot.stackSize == 0) getSlot(i).putStack(null);
stackSlot.shrink(1);
if (stackSlot.isEmpty()) getSlot(i).putStack(ItemStack.EMPTY);
}
}
}
Expand All @@ -122,10 +117,11 @@ else if (mousebtn == 1)
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slots)
{
if (slots < 10 || slots == RETURN_SLOT_ID) ((Slot) inventorySlots.get(slots)).putStack(null);
return null;
if (slots < 10 || slots == RETURN_SLOT_ID) inventorySlots.get(slots).putStack(ItemStack.EMPTY);
return ItemStack.EMPTY;
}

// public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_)
Expand Down
44 changes: 26 additions & 18 deletions src/main/java/net/doubledoordev/mtrm/gui/MTRMGui.java
@@ -1,6 +1,8 @@
package net.doubledoordev.mtrm.gui;

import com.sun.istack.internal.NotNull;
import net.doubledoordev.mtrm.MineTweakerRecipeMaker;
import net.doubledoordev.mtrm.network.MessageResponse;
import net.doubledoordev.mtrm.network.MessageSend;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
Expand Down Expand Up @@ -111,6 +113,7 @@ public void onChangeSliderValue(GuiSlider slider)
private MessageSend messageSend = new MessageSend();
private int editing = -1;
private int lastOreId = 0;
private MessageResponse.Status status;
private String errorMessage;

public MTRMGui(MTRMContainer container)
Expand All @@ -120,11 +123,15 @@ public MTRMGui(MTRMContainer container)
this.container = container;
}

public String getStackToken(boolean nextOreDict, ItemStack stack)
public String getStackToken(boolean nextOreDict, @NotNull ItemStack stack)
{
boolean metaWildcard = this.metaWildcard.isChecked();
boolean oreDict = this.oreDict.isChecked();
if (stack == null) return "null";
if (stack.isEmpty()) return "null";
if (stack.getItem().getRegistryName() == null)
{
throw new IllegalStateException("PLEASE REPORT: Item not empty, but getRegistryName null? Debug info: " + stack);
}
String stackName = stack.getItem().getRegistryName().toString();
StringBuilder builder = new StringBuilder("<");
if (oreDict)
Expand All @@ -141,7 +148,7 @@ public String getStackToken(boolean nextOreDict, ItemStack stack)
builder.append(stackName);
if (!oreDict && (metaWildcard || stack.getItemDamage() != 0)) builder.append(':').append(metaWildcard || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? "*" : stack.getItemDamage());
builder.append('>');
if (stack.stackSize > 1) builder.append(" * ").append(stack.stackSize);
if (stack.getCount() > 1) builder.append(" * ").append(stack.getCount());
if (anyDamage.isChecked()) builder.append(".anyDamage()");
if (onlyDamaged.isChecked()) builder.append(".onlyDamaged()");
if (withDamage.isChecked()) builder.append(".withDamage(").append(sliders.get(withDamage)[0].getValueInt()).append(')');
Expand All @@ -161,7 +168,7 @@ public String getStackToken(boolean nextOreDict, ItemStack stack)
builder.append(returnStack.getItem().getRegistryName());
if (returnStack.getItemDamage() != 0) builder.append(':').append(returnStack.getItemDamage());
builder.append('>');
if (returnStack.stackSize > 1) builder.append(" * ").append(returnStack.stackSize);
if (returnStack.getCount() > 1) builder.append(" * ").append(returnStack.getCount());
builder.append(')');
}
return builder.toString();
Expand All @@ -185,7 +192,7 @@ public void initGui()
int wOffset = this.width / 2 - 200;
int hOffset = this.height / 2 - 110;

tokenTxt = new GuiTextField(0, this.fontRendererObj, wOffset, hOffset - 25, 220 + this.xSize, 20);
tokenTxt = new GuiTextField(0, this.fontRenderer, wOffset, hOffset - 25, 220 + this.xSize, 20);
tokenTxt.setMaxStringLength(Integer.MAX_VALUE);

this.buttonList.add(matchAll = new GuiCheckBox(ID_OPTION_MATCHALL, wOffset, hOffset += 10, "Match not empty (*)", false));
Expand Down Expand Up @@ -309,7 +316,7 @@ protected void actionPerformed(GuiButton btn)
switch (btn.id)
{
case ID_CLOSE:
this.mc.thePlayer.closeScreen();
this.mc.player.closeScreen();
break;
case ID_SEND:
messageSend.remove = remove.isChecked();
Expand Down Expand Up @@ -412,7 +419,7 @@ private void showOptionsFor(int id)
if (labels.containsKey(checkBox)) for (GuiCustomLabel l : labels.get(checkBox)) l.draw = false;
}
}
container.getSlot(RETURN_SLOT_ID).putStack(null);
container.getSlot(RETURN_SLOT_ID).putStack(ItemStack.EMPTY);
}
else
{
Expand Down Expand Up @@ -459,7 +466,7 @@ private void showOptionsFor(int id)
if (!oreDict.isChecked())
{
ItemStack stack = container.getSlot(editing).getStack();
if (stack != null) slider.maxValue = stack.getItem().getMaxDamage();
if (!stack.isEmpty()) slider.maxValue = stack.getMaxDamage();
}
}
if (token != null && patterns.containsKey(checkBox))
Expand Down Expand Up @@ -504,7 +511,7 @@ private void setOptionsVisible(boolean visible)

tokenTxt.setVisible(visible);

if (!visible) container.putStackInSlot(RETURN_SLOT_ID, null);
if (!visible) container.putStackInSlot(RETURN_SLOT_ID, ItemStack.EMPTY);
}

// protected void keyTyped(char p_73869_1_, int p_73869_2_)
Expand All @@ -528,15 +535,16 @@ protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_)
{
if (editing != -1)
{
this.fontRendererObj.drawString("Editing slot " + editing, -110, -55, 0xFFFFFF);
this.fontRendererObj.drawString("Slot Options", -100, -20, 0xFFFFFF);
this.fontRenderer.drawString("Editing slot " + editing, -110, -55, 0xFFFFFF);
this.fontRenderer.drawString("Slot Options", -100, -20, 0xFFFFFF);
}
this.fontRendererObj.drawString("Recipe Options", this.xSize + 15, 0, 0xFFFFFF);
this.fontRendererObj.drawString("MineTweaker Recipe Maker", 28, 4, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 5, 4210752);
if (errorMessage != null) this.drawCenteredString(this.fontRendererObj, errorMessage, this.xSize / 2, -15, 0xFF0000);
this.fontRendererObj.drawString("0", 144, 53, 0xFFFFFF);
for (int y = 0; y < 3; ++y) for (int x = 0; x < 3; ++x) this.fontRendererObj.drawString(String.valueOf(1 + y * 3 + x), 28 + x * 26, 25 + y * 26, 0xFFFFFF);
this.fontRenderer.drawString("Recipe Options", this.xSize + 15, 0, 0xFFFFFF);
this.fontRenderer.drawString("MineTweaker Recipe Maker", 28, 4, 4210752);
this.fontRenderer.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 5, 4210752);
if (errorMessage != null)
this.drawCenteredString(this.fontRenderer, errorMessage, this.xSize / 2, -15, 0xFF0000);
this.fontRenderer.drawString("0", 144, 53, 0xFFFFFF);
for (int y = 0; y < 3; ++y) for (int x = 0; x < 3; ++x) this.fontRenderer.drawString(String.valueOf(1 + y * 3 + x), 28 + x * 26, 25 + y * 26, 0xFFFFFF);
for (GuiCustomLabel[] labela : labels.values()) for (GuiCustomLabel label : labela) if (label.draw) label.draw(true);
}

Expand Down Expand Up @@ -578,7 +586,7 @@ public GuiCustomLabelText(String s, int x, int y)

public void draw(boolean b)
{
if (b) fontRendererObj.drawString(text, x, y, color);
if (b) fontRenderer.drawString(text, x, y, color);
}
}
}
29 changes: 23 additions & 6 deletions src/main/java/net/doubledoordev/mtrm/network/MessageResponse.java
@@ -1,8 +1,12 @@
package net.doubledoordev.mtrm.network;

import io.netty.buffer.ByteBuf;
import net.doubledoordev.mtrm.MineTweakerRecipeMaker;
import net.doubledoordev.mtrm.gui.MTRMGui;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
Expand All @@ -13,6 +17,7 @@
*/
public class MessageResponse implements IMessage
{
private Status status;
private String message;

public MessageResponse()
Expand All @@ -21,19 +26,21 @@ public MessageResponse()

public MessageResponse(Status status, Object... args)
{
this.status = status;
this.message = status.message == null ? null : String.format(status.message, args);
}

@Override
public void fromBytes(ByteBuf buf)
{
if (buf.readBoolean()) message = ByteBufUtils.readUTF8String(buf);
this.status = Status.values()[buf.readByte()];
if (this.status.message != null) message = ByteBufUtils.readUTF8String(buf);
}

@Override
public void toBytes(ByteBuf buf)
{
buf.writeBoolean(message != null);
buf.writeByte(status.ordinal());
if (message != null) ByteBufUtils.writeUTF8String(buf, message);
}

Expand All @@ -42,16 +49,26 @@ public static class Handler implements IMessageHandler<MessageResponse, IMessage
@Override
public IMessage onMessage(MessageResponse message, MessageContext ctx)
{
if (Minecraft.getMinecraft().currentScreen instanceof MTRMGui)
if (message.status == Status.OK)
{
MTRMGui gui = ((MTRMGui) Minecraft.getMinecraft().currentScreen);
gui.showMessage(message.message);
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Saved recipe change.").setStyle(new Style().setColor(TextFormatting.GREEN)));
}
else
{
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(message.message).setStyle(new Style().setColor(TextFormatting.RED)));
MineTweakerRecipeMaker.getLogger().info("Something went wrong: {}. Message: {}", message.status.name(), message.message);
if (Minecraft.getMinecraft().currentScreen instanceof MTRMGui)
{
// Fixme: IntelliJ are you drunk?
//noinspection ConstantConditions
((MTRMGui) Minecraft.getMinecraft().currentScreen).showMessage(message.message);
}
}
return null;
}
}

public static enum Status
public enum Status
{
OK(null), NO_OUT("There is no output specified."), NO_IN("There is no input specified."), WRITE_ERROR("IOError: %s");
private final String message;
Expand Down

0 comments on commit 1129d1a

Please sign in to comment.