Bags of Holding will show their custom name in their interface

This commit is contained in:
Sollace 2018-09-19 10:17:18 +02:00
parent 75ee2c9697
commit 2549cfe1ae
5 changed files with 56 additions and 36 deletions

View file

@ -16,8 +16,12 @@ public final class Predicates {
return player != null && PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canCast(); return player != null && PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canCast();
}; };
public static final Predicate<Entity> ITEMS = entity -> {
return entity.isEntityAlive() && entity instanceof EntityItem;
};
public static final Predicate<EntityItem> ITEM_INTERACT_WITH_CLOUDS = item -> { public static final Predicate<EntityItem> ITEM_INTERACT_WITH_CLOUDS = item -> {
return item != null && PlayerSpeciesList.instance().getEntity(item).getPlayerSpecies().canInteractWithClouds(); return ITEMS.test(item) && PlayerSpeciesList.instance().getEntity(item).getPlayerSpecies().canInteractWithClouds();
}; };
public static final Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = entity -> { public static final Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = entity -> {

View file

@ -7,8 +7,9 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.IWorldNameable;
public class ContainerOfHolding extends Container { public class ContainerOfHolding extends Container implements IWorldNameable {
private final InventoryOfHolding inventory; private final InventoryOfHolding inventory;
@ -54,6 +55,18 @@ public class ContainerOfHolding extends Container {
return true; return true;
} }
@Override
public String getName() {
return getDisplayName().getUnformattedText();
}
@Override
public boolean hasCustomName() {
return inventory.hasCustomName();
}
@Override
public ITextComponent getDisplayName() { public ITextComponent getDisplayName() {
return inventory.getDisplayName(); return inventory.getDisplayName();
} }

View file

@ -45,7 +45,13 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab
return true; return true;
}); });
return new InventoryOfHolding(items); InventoryOfHolding result = new InventoryOfHolding(items);
if (stack.hasDisplayName()) {
result.setCustomName(stack.getDisplayName());
}
return result;
} }
public static void iterateContents(ItemStack stack, BiFunction<Integer, ItemStack, Boolean> itemConsumer) { public static void iterateContents(ItemStack stack, BiFunction<Integer, ItemStack, Boolean> itemConsumer) {
@ -69,12 +75,14 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab
private InventoryOfHolding(List<ItemStack> items) { private InventoryOfHolding(List<ItemStack> items) {
super("unicopia.gui.title.bagofholding", false, items.size() + 9 - (items.size() % 9)); super("unicopia.gui.title.bagofholding", false, items.size() + 9 - (items.size() % 9));
for (int i = 0; i < items.size(); i++) { for (int i = 0; i < items.size(); i++) {
setInventorySlotContents(i, items.get(i)); setInventorySlotContents(i, items.get(i));
} }
} }
public <T extends TileEntity & IInventory> void addBlockEntity(World world, BlockPos pos, IBlockState state, T blockInventory) { public <T extends TileEntity & IInventory> void addBlockEntity(World world, BlockPos pos, T blockInventory) {
IBlockState state = world.getBlockState(pos);
ItemStack blockStack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); ItemStack blockStack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state));
blockInventory.writeToNBT(blockStack.getOrCreateSubCompound("BlockEntityTag")); blockInventory.writeToNBT(blockStack.getOrCreateSubCompound("BlockEntityTag"));

View file

@ -88,7 +88,7 @@ public class GuiOfHolding extends GuiContainer {
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
ContainerOfHolding coh = (ContainerOfHolding)inventorySlots; ContainerOfHolding coh = (ContainerOfHolding)inventorySlots;
fontRenderer.drawString(coh.getDisplayName().getUnformattedText(), 8, 6, 4210752); fontRenderer.drawString(coh.getName(), 8, 6, 0x404040);
} }
@Override @Override

View file

@ -13,13 +13,11 @@ import com.minelittlepony.unicopia.inventory.InventoryOfHolding;
import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding;
import com.minelittlepony.util.vector.VecHelper; import com.minelittlepony.util.vector.VecHelper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
@ -36,6 +34,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IInteractionObject; import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -83,13 +82,12 @@ public class ItemOfHolding extends Item implements IMagicalItem {
if (hit.typeOfHit == RayTraceResult.Type.BLOCK) { if (hit.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos pos = hit.getBlockPos(); BlockPos pos = hit.getBlockPos();
IBlockState state = world.getBlockState(pos);
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof IInventory) { if (tile instanceof IInventory) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
inventory.addBlockEntity(world, pos, state, (TileEntity & IInventory)tile); inventory.addBlockEntity(world, pos, (TileEntity & IInventory)tile);
inventory.writeTostack(stack); inventory.writeTostack(stack);
inventory.closeInventory(player); inventory.closeInventory(player);
@ -98,7 +96,7 @@ public class ItemOfHolding extends Item implements IMagicalItem {
AxisAlignedBB box = new AxisAlignedBB(pos.offset(hit.sideHit)).grow(0.5); AxisAlignedBB box = new AxisAlignedBB(pos.offset(hit.sideHit)).grow(0.5);
List<Entity> itemsAround = world.getEntitiesInAABBexcluding(player, box, e -> e.isEntityAlive() && e instanceof EntityItem); List<Entity> itemsAround = world.getEntitiesInAABBexcluding(player, box, Predicates.ITEMS);
if (itemsAround.size() > 0) { if (itemsAround.size() > 0) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
@ -109,40 +107,34 @@ public class ItemOfHolding extends Item implements IMagicalItem {
return new ActionResult<>(EnumActionResult.SUCCESS, stack); return new ActionResult<>(EnumActionResult.SUCCESS, stack);
} }
} else if (hit.typeOfHit == RayTraceResult.Type.ENTITY && hit.entityHit instanceof EntityLiving) {
/*if (!(hit.entityHit instanceof EntityPlayer)) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
inventory.addPrisoner((EntityLiving)hit.entityHit);
inventory.writeTostack(stack);
inventory.closeInventory(player);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}*/
} }
} }
return new ActionResult<>(EnumActionResult.FAIL, stack); return new ActionResult<>(EnumActionResult.FAIL, stack);
} else {
IInteractionObject inventory = new Inventory();
if (UClient.isClientSide() && player instanceof EntityPlayerSP) {
Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory));
player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1);
} else {
player.displayGui(inventory);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
} }
IInteractionObject inventory = new Inventory(stack);
if (UClient.isClientSide() && player instanceof EntityPlayerSP) {
Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory));
player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1);
} else {
player.displayGui(inventory);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
} }
public class Inventory implements IInteractionObject { public class Inventory implements IInteractionObject {
private String customname = null;
Inventory(ItemStack stack) {
if (stack.hasDisplayName()) {
customname = stack.getDisplayName();
}
}
@Override @Override
public String getName() { public String getName() {
return "unicopi.gui.title.itemofholding"; return "unicopi.gui.title.itemofholding";
@ -150,11 +142,14 @@ public class ItemOfHolding extends Item implements IMagicalItem {
@Override @Override
public boolean hasCustomName() { public boolean hasCustomName() {
return false; return customname != null;
} }
@Override @Override
public ITextComponent getDisplayName() { public ITextComponent getDisplayName() {
if (hasCustomName()) {
return new TextComponentString(customname);
}
return new TextComponentTranslation(getName()); return new TextComponentTranslation(getName());
} }