forked from cpw/ironchest
-
Notifications
You must be signed in to change notification settings - Fork 87
/
DirtChestBlockEntity.java
73 lines (58 loc) · 3.03 KB
/
DirtChestBlockEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.progwml6.ironchest.common.block.regular.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.state.BlockState;
import javax.annotation.Nullable;
import java.util.Objects;
public class DirtChestBlockEntity extends AbstractIronChestBlockEntity {
private static ItemStack DIRT_CHEST_BOOK = new ItemStack(Items.WRITTEN_BOOK);
private static boolean bookDataCreated = false;
public DirtChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.DIRT_CHEST.get(), blockPos, blockState, IronChestsTypes.DIRT, IronChestsBlocks.DIRT_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createDirtContainer(containerId, playerInventory, this);
}
@Override
public void wasPlaced(@Nullable LivingEntity livingEntity, ItemStack itemStack) {
if (!(itemStack.hasTag() && Objects.requireNonNull(itemStack.getTag()).getBoolean("been_placed"))) {
//TODO FIX BOOK
//this.setInventorySlotContents(0, DIRT_CHEST_BOOK.copy());
}
if (!bookDataCreated) {
//createBookData();
}
}
@Override
public void removeAdornments() {
if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).sameItem(DIRT_CHEST_BOOK)) {
this.getItems().set(0, ItemStack.EMPTY);
}
}
private static void createBookData() {
DIRT_CHEST_BOOK.addTagElement("author", StringTag.valueOf("cpw"));
DIRT_CHEST_BOOK.addTagElement("title", StringTag.valueOf(I18n.get("book.ironchest.dirtchest9000.title")));
ListTag pages = new ListTag();
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page1"))));
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page2"))));
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page3"))));
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page4"))));
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page5"))));
DIRT_CHEST_BOOK.addTagElement("pages", pages);
bookDataCreated = true;
}
}