forked from cpw/ironchest
-
Notifications
You must be signed in to change notification settings - Fork 87
/
IronChestBlockItem.java
85 lines (73 loc) · 5.22 KB
/
IronChestBlockItem.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
74
75
76
77
78
79
80
81
82
83
84
85
package com.progwml6.ironchest.common.item;
import com.progwml6.ironchest.client.model.inventory.IronChestItemStackRenderer;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.regular.entity.CopperChestBlockEntity;
import com.progwml6.ironchest.common.block.regular.entity.CrystalChestBlockEntity;
import com.progwml6.ironchest.common.block.regular.entity.DiamondChestBlockEntity;
import com.progwml6.ironchest.common.block.regular.entity.DirtChestBlockEntity;
import com.progwml6.ironchest.common.block.regular.entity.GoldChestBlockEntity;
import com.progwml6.ironchest.common.block.regular.entity.IronChestBlockEntity;
import com.progwml6.ironchest.common.block.regular.entity.ObsidianChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedCopperChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedCrystalChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedDiamondChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedDirtChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedGoldChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedIronChestBlockEntity;
import com.progwml6.ironchest.common.block.trapped.entity.TrappedObsidianChestBlockEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.IItemRenderProperties;
import net.minecraftforge.fml.DistExecutor;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class IronChestBlockItem extends BlockItem {
protected Supplier<IronChestsTypes> type;
protected Supplier<Boolean> trapped;
public IronChestBlockItem(Block block, Properties properties, Supplier<Callable<IronChestsTypes>> type, Supplier<Callable<Boolean>> trapped) {
super(block, properties);
IronChestsTypes tempType = DistExecutor.callWhenOn(Dist.CLIENT, type);
Boolean tempTrapped = DistExecutor.callWhenOn(Dist.CLIENT, trapped);
this.type = tempType == null ? null : () -> tempType;
this.trapped = tempTrapped == null ? null : () -> tempTrapped;
}
@Override
public void initializeClient(Consumer<IItemRenderProperties> consumer) {
super.initializeClient(consumer);
consumer.accept(new IItemRenderProperties() {
@Override
public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
Supplier<BlockEntity> modelToUse;
if (trapped.get()) {
switch (type.get()) {
case GOLD -> modelToUse = () -> new TrappedGoldChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_GOLD_CHEST.get().defaultBlockState());
case DIAMOND -> modelToUse = () -> new TrappedDiamondChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_DIAMOND_CHEST.get().defaultBlockState());
case COPPER -> modelToUse = () -> new TrappedCopperChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_COPPER_CHEST.get().defaultBlockState());
case CRYSTAL -> modelToUse = () -> new TrappedCrystalChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_CRYSTAL_CHEST.get().defaultBlockState());
case OBSIDIAN -> modelToUse = () -> new TrappedObsidianChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_OBSIDIAN_CHEST.get().defaultBlockState());
case DIRT -> modelToUse = () -> new TrappedDirtChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_DIRT_CHEST.get().defaultBlockState());
default -> modelToUse = () -> new TrappedIronChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.TRAPPED_IRON_CHEST.get().defaultBlockState());
}
} else {
switch (type.get()) {
case GOLD -> modelToUse = () -> new GoldChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.GOLD_CHEST.get().defaultBlockState());
case DIAMOND -> modelToUse = () -> new DiamondChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIAMOND_CHEST.get().defaultBlockState());
case COPPER -> modelToUse = () -> new CopperChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.COPPER_CHEST.get().defaultBlockState());
case CRYSTAL -> modelToUse = () -> new CrystalChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.CRYSTAL_CHEST.get().defaultBlockState());
case OBSIDIAN -> modelToUse = () -> new ObsidianChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.OBSIDIAN_CHEST.get().defaultBlockState());
case DIRT -> modelToUse = () -> new DirtChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIRT_CHEST.get().defaultBlockState());
default -> modelToUse = () -> new IronChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.IRON_CHEST.get().defaultBlockState());
}
}
return new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), modelToUse);
}
});
}
}