Fixes for the previous commits

This commit is contained in:
malte0811 2017-05-26 13:26:15 +02:00
parent 55e03ab8a4
commit b11ca376a3
7 changed files with 40 additions and 30 deletions

View file

@ -30,7 +30,7 @@ public class IWConfig {
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
public static boolean enableConversion = true;
public static MechConversion mech;
public static MechConversion mech = new MechConversion();
public static class MechConversion {
@Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 0.25)"})
@ -54,7 +54,7 @@ public class IWConfig {
public static double kinToRotEfficiency = .8;
}
public static HVStuff hv;
public static HVStuff hv = new HVStuff();
public static class HVStuff {
@Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"})

View file

@ -45,11 +45,13 @@ public class GuiRenameKey extends GuiContainer {
@Override
public void initGui() {
super.initGui();
field = new GuiTextField(0, mc.fontRenderer, (width-58)/2, (height-12)/2, 58, 12);
ItemStack held = mc.player.getHeldItem(hand);
NBTTagCompound nbt = held.getTagCompound();
if (nbt!=null&&nbt.hasKey("name")) {
field.setText(nbt.getString("name"));
field = new GuiTextField(0, mc.fontRendererObj, (width-58)/2, (height-12)/2, 58, 12);
ItemStack held = mc.thePlayer.getHeldItem(hand);
if (held!=null) {
NBTTagCompound nbt = held.getTagCompound();
if (nbt != null && nbt.hasKey("name")) {
field.setText(nbt.getString("name"));
}
}
xSize = 64;
ySize = 64;

View file

@ -165,15 +165,15 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
if (keyNBT == null) {
for (EnumHand hand : EnumHand.values()) {
ItemStack held = player.getHeldItem(hand);
if (held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) {
if (held!=null && held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) {
keyNBT = held.serializeNBT();
player.setHeldItem(hand, ItemStack.EMPTY);
player.setHeldItem(hand, null);
break;
}
}
} else if (!turned) {
if (player.isSneaking() && player.getHeldItemMainhand().isEmpty()) {
player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(keyNBT));
if (player.isSneaking() && player.getHeldItemMainhand()== null) {
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.loadItemStackFromNBT(keyNBT));
keyNBT = null;
} else {
turned = true;

View file

@ -25,10 +25,11 @@ import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
//TODO JEI
public class RecipeKeyLock implements IRecipe {
@ -40,7 +41,11 @@ public class RecipeKeyLock implements IRecipe {
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack ret = getKey(inv).copy();
ItemStack key = getKey(inv);
if (key==null) {
return null;
}
ItemStack ret = key.copy();
ItemKey.setId(ret, getLockId(inv));
return ret;
}
@ -58,12 +63,12 @@ public class RecipeKeyLock implements IRecipe {
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < ret.size(); i++) {
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
for (int i = 0; i < ret.length; i++) {
ItemStack here = inv.getStackInSlot(i);
if (here.getItem() == IndustrialWires.panelComponent) {
ret.set(i, here);
if (here!=null && here.getItem() == IndustrialWires.panelComponent) {
ret[i] = here;
}
}
return ret;
@ -74,12 +79,12 @@ public class RecipeKeyLock implements IRecipe {
boolean hasKey = false;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack here = inv.getStackInSlot(i);
if (here.getItem() == IndustrialWires.key) {
if (here!=null && here.getItem() == IndustrialWires.key) {
if (hasKey || ItemKey.idForKey(here) != 0) {//too many keys or non-blanks
return 0;
}
hasKey = true;
} else if (here.getItem() == IndustrialWires.panelComponent) {
} else if (here != null && here.getItem() == IndustrialWires.panelComponent) {
if (id != 0) {//too many locks/components
return 0;
}
@ -97,15 +102,15 @@ public class RecipeKeyLock implements IRecipe {
return id;
}
@Nonnull
@Nullable
//assumes that the recipe is valid
private ItemStack getKey(@Nonnull InventoryCrafting inv) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack here = inv.getStackInSlot(i);
if (here.getItem() == IndustrialWires.key) {
if (here!=null && here.getItem() == IndustrialWires.key) {
return here;
}
}
return ItemStack.EMPTY;
return null;
}
}

View file

@ -40,7 +40,10 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;

View file

@ -86,13 +86,13 @@ public class ItemKey extends Item implements INetGUIItem {
return 1;
}
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
if (!worldIn.isRemote) {
playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0);
}
return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
@Override

View file

@ -56,10 +56,10 @@ public class MessageItemSync implements IMessage {
public static class HandlerServer implements IMessageHandler<MessageItemSync, IMessage> {
@Override
public IMessage onMessage(MessageItemSync message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().player;
EntityPlayer player = ctx.getServerHandler().playerEntity;
ItemStack held = player.getHeldItem(message.hand);
if (held.getItem() instanceof INetGUIItem) {
ctx.getServerHandler().player.getServerWorld().addScheduledTask(() ->
if (held!=null && held.getItem() instanceof INetGUIItem) {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(() ->
((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand));
}
return null;