improve renaming and cheats
This commit is contained in:
parent
4d406a70e1
commit
7e9673dc25
36 changed files with 346 additions and 186 deletions
|
@ -126,6 +126,19 @@ public abstract class Container
|
|||
return slot != null ? slot.getStack() : null;
|
||||
}
|
||||
|
||||
public void renameItem(int id, String name) {
|
||||
if(id < 0 || id >= this.inventorySlots.size())
|
||||
return;
|
||||
Slot slot = this.inventorySlots.get(id);
|
||||
if(slot != null && slot.canEditItem() && slot.getHasStack()) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if(name.isBlank())
|
||||
stack.clearCustomName();
|
||||
else
|
||||
stack.setStackDisplayName(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles slot click.
|
||||
*/
|
||||
|
|
|
@ -186,6 +186,10 @@ public class ContainerBrewingStand extends Container
|
|||
return 1;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
// {
|
||||
// if (stack.getItem() == Items.potion && stack.getMetadata() > 0)
|
||||
|
|
|
@ -59,6 +59,10 @@ public class ContainerEnchantment extends Container
|
|||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
|
|
|
@ -15,8 +15,16 @@ public class ContainerMerchant extends Container
|
|||
this.theMerchant = merchant;
|
||||
this.theWorld = worldIn;
|
||||
this.merchantInventory = new InventoryMerchant(playerInventory.player, merchant);
|
||||
this.addSlotToContainer(new Slot(this.merchantInventory, 0, 36, 53));
|
||||
this.addSlotToContainer(new Slot(this.merchantInventory, 1, 62, 53));
|
||||
this.addSlotToContainer(new Slot(this.merchantInventory, 0, 36, 53) {
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.addSlotToContainer(new Slot(this.merchantInventory, 1, 62, 53) {
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.addSlotToContainer(new SlotMerchantResult(playerInventory.player, this.merchantInventory, 2, 120, 53));
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
|
|
|
@ -30,7 +30,11 @@ public class ContainerPlayer extends Container
|
|||
{
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18));
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18) {
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,16 @@ public class ContainerRepair extends Container
|
|||
this.selfPosition = blockPosIn;
|
||||
this.theWorld = worldIn;
|
||||
this.thePlayer = player;
|
||||
this.addSlotToContainer(new Slot(this.inputSlots, 0, 27, 47));
|
||||
this.addSlotToContainer(new Slot(this.inputSlots, 1, 76, 47));
|
||||
this.addSlotToContainer(new Slot(this.inputSlots, 0, 27, 47) {
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.addSlotToContainer(new Slot(this.inputSlots, 1, 76, 47) {
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.addSlotToContainer(new Slot(this.outputSlot, 2, 134, 47)
|
||||
{
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
|
@ -120,6 +128,10 @@ public class ContainerRepair extends Container
|
|||
worldIn.playAuxSFX(1021, blockPosIn, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
|
|
|
@ -30,7 +30,11 @@ public class ContainerWorkbench extends Container
|
|||
{
|
||||
for (int j = 0; j < size; ++j)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * size, 26 + j * 18, 17 + i * 18));
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * size, 26 + j * 18, 17 + i * 18) {
|
||||
public boolean canEditItem() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,4 +164,12 @@ public class Slot
|
|||
public int getIndex() {
|
||||
return this.slotIndex;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canEditItem() {
|
||||
return this.canCheatItem();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,4 +152,8 @@ public class SlotCrafting extends Slot
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,4 +105,8 @@ public class SlotFurnaceOutput extends Slot
|
|||
// this.thePlayer.triggerAchievement(AchievementList.cookFish);
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,4 +115,8 @@ public class SlotMerchantResult extends Slot
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,27 +10,38 @@ public class CPacketMessage implements Packet<IPlayer>
|
|||
{
|
||||
private Type type;
|
||||
private String message;
|
||||
private int arg;
|
||||
|
||||
public CPacketMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public CPacketMessage(Type type, String str)
|
||||
{
|
||||
this(type, str, 0);
|
||||
}
|
||||
|
||||
public CPacketMessage(Type type, String str, int arg)
|
||||
{
|
||||
this.type = type;
|
||||
this.message = str.length() > type.length ? str.substring(0, type.length) :str;
|
||||
this.message = str.length() > type.length ? str.substring(0, type.length) : str;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public void readPacketData(PacketBuffer buf) throws IOException
|
||||
{
|
||||
this.type = buf.readEnumValue(Type.class);
|
||||
this.message = buf.readString(this.type.length);
|
||||
if(this.type.hasArg)
|
||||
this.arg = buf.readVarInt();
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException
|
||||
{
|
||||
buf.writeEnumValue(this.type);
|
||||
buf.writeString(this.message);
|
||||
if(this.type.hasArg)
|
||||
buf.writeVarInt(this.arg);
|
||||
}
|
||||
|
||||
public void processPacket(IPlayer handler)
|
||||
|
@ -47,18 +58,29 @@ public class CPacketMessage implements Packet<IPlayer>
|
|||
{
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public int getArg()
|
||||
{
|
||||
return this.arg;
|
||||
}
|
||||
|
||||
public static enum Type {
|
||||
COMMAND(IPlayer.MAX_CMD_LENGTH),
|
||||
CHAT(IPlayer.MAX_CMD_LENGTH),
|
||||
DISPLAY(IPlayer.MAX_NICK_LENGTH),
|
||||
INFO(IPlayer.MAX_INFO_LENGTH);
|
||||
// , ITEM(30);
|
||||
INFO(IPlayer.MAX_INFO_LENGTH),
|
||||
ITEM(30, true);
|
||||
|
||||
private final int length;
|
||||
private final boolean hasArg;
|
||||
|
||||
private Type(int length, boolean hasArg) {
|
||||
this.length = length;
|
||||
this.hasArg = hasArg;
|
||||
}
|
||||
|
||||
private Type(int length) {
|
||||
this.length = length;
|
||||
this(length, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue