ItemObituariy: finish implementation
parent
1b347a5490
commit
0831ad4b2f
|
@ -14,6 +14,7 @@ import net.minecraft.block.BlockAir;
|
|||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
|
||||
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
||||
|
@ -34,6 +35,8 @@ public class EventHook {
|
|||
Debug.out("X: " + Long.toString(x));
|
||||
Debug.out("Y: " + Long.toString(y));
|
||||
Debug.out("Z: " + Long.toString(z));
|
||||
|
||||
//TODO: Don’t place a death chest for an empty inventory
|
||||
|
||||
// Don’t place the chest outside the world
|
||||
if (y < 0) y = 0;
|
||||
|
@ -179,6 +182,7 @@ public class EventHook {
|
|||
Debug.out(uuid);
|
||||
DeathChestStorage.addNewDeathChestLocation(uuid, suitableBlock);
|
||||
|
||||
//TODO: prevent the items in question from spawning instead of canceling the event
|
||||
event.setCanceled(true);
|
||||
Debug.out("Canceled PlayerDropEvent");
|
||||
} else {
|
||||
|
@ -202,12 +206,23 @@ public class EventHook {
|
|||
Debug.out("Chest location dimension: " + Integer.toString(chestLocation[3]));
|
||||
|
||||
if (Config.giveObituary) {
|
||||
//TODO: NBT data
|
||||
event.player.inventory.addItemStackToInventory(new ItemStack(ItemObituary.getInstance()));
|
||||
ItemStack stack = new ItemStack(ItemObituary.getInstance());
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
String location = Integer.toString(chestLocation[0]) + " " + Integer.toString(chestLocation[1]) + " " + Integer.toString(chestLocation[2]);
|
||||
//TODO: Find the name of the dimension instead
|
||||
String dimension = Integer.toString(chestLocation[3]);
|
||||
String message = String.format(Config.locationMessage, location, dimension);
|
||||
compound.setString("message", message);
|
||||
stack.setTagCompound(compound);
|
||||
event.player.inventory.addItemStackToInventory(stack);
|
||||
}
|
||||
} else {
|
||||
Debug.out("No death chest location was stored.");
|
||||
//TODO: tell player that a death chest couldn’t be placed and that the items have been dropped
|
||||
ItemStack stack = new ItemStack(ItemObituary.getInstance());
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setString("message", Config.dropMessage);
|
||||
stack.setTagCompound(compound);
|
||||
event.player.inventory.addItemStackToInventory(stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
package lostcave.deathchests.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lostcave.deathchests.util.Config;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemObituary extends Item {
|
||||
|
||||
|
@ -13,9 +21,28 @@ public class ItemObituary extends Item {
|
|||
private ItemObituary() {
|
||||
this.setUnlocalizedName("obituary");
|
||||
this.setTextureName("paper");
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
if (world.isRemote) return stack;
|
||||
|
||||
String chatMessage = "§4Error: Missing data";
|
||||
if (stack.hasTagCompound()) {
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
if (compound.hasKey("message")) {
|
||||
chatMessage = compound.getString("message");
|
||||
}
|
||||
}
|
||||
player.addChatMessage(new ChatComponentText(chatMessage));
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
//TODO: NBT data
|
||||
//TODO: right click action
|
||||
//TODO: item description
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List lores, boolean bool) {
|
||||
lores.add("Right-click me!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ public class Config {
|
|||
public static boolean allowOtherPlayers = true;
|
||||
public static String notAllowedMessage = "§4Cannot get items from another player's death chest.";
|
||||
public static boolean giveObituary = true;
|
||||
public static String dropMessage = "§4A death chest could not be placed for this death. Your items have been dropped.";
|
||||
public static String locationMessage = "§eThe death chest for this death is at %s in dimension %s.";
|
||||
|
||||
private static final String config_header = "# The format of this file is strictly `option=value` (no spaces).\n# Lines starting with # and empty lines are ignored.";
|
||||
|
||||
|
@ -41,6 +43,12 @@ public class Config {
|
|||
configOut += "\n\n# Whether to give respawning players an obituary item\n";
|
||||
configOut += "giveObituary=";
|
||||
configOut += giveObituary ? "true" : "false";
|
||||
configOut += "\n\n# The message to display when no suitable location for a death chest could be found and the items have been dropped";
|
||||
configOut += "dropMessage=";
|
||||
configOut += dropMessage;
|
||||
configOut += "\n\n# The message to display when no suitable location for a death chest could be found and the items have been dropped";
|
||||
configOut += "locationMessage=";
|
||||
configOut += locationMessage;
|
||||
|
||||
File configFile = new File(configDir, config_file_name);
|
||||
try {
|
||||
|
@ -86,6 +94,14 @@ public class Config {
|
|||
giveObituary = configData.get(i).substring(equalsSign + 1).equals("true") ? true : false;
|
||||
break;
|
||||
}
|
||||
case ("dropMessage"): {
|
||||
dropMessage = configData.get(i).substring(equalsSign+1);
|
||||
break;
|
||||
}
|
||||
case ("locationMessage"): {
|
||||
locationMessage = configData.get(i).substring(equalsSign+1);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
System.err.println("Failed parsing config entry: " + configData.get(i));
|
||||
FMLCommonHandler.instance().exitJava(1, false);
|
||||
|
|
Loading…
Reference in New Issue