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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
package gtPlusPlus.core.block.machine;
import static gregtech.api.enums.Mods.GTPlusPlus;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import com.cleanroommc.modularui.factory.GuiFactories;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.api.interfaces.ITileTooltip;
import gtPlusPlus.core.client.renderer.RenderDecayChest;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.item.base.itemblock.ItemBlockBasicTile;
import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest;
import gtPlusPlus.core.util.minecraft.InventoryUtils;
public class BlockDecayablesChest extends BlockContainer implements ITileTooltip {
@SideOnly(Side.CLIENT)
private IIcon textureTop;
@SideOnly(Side.CLIENT)
private IIcon textureBottom;
@SideOnly(Side.CLIENT)
private IIcon textureSide;
/**
* Determines which tooltip is displayed within the itemblock.
*/
private final int mTooltipID = 3;
@Override
public int getTooltipID() {
return this.mTooltipID;
}
public BlockDecayablesChest() {
super(Material.iron);
this.setBlockName("blockDecayablesChest");
this.setCreativeTab(AddToCreativeTab.tabMachines);
this.setHardness(5f);
this.setResistance(1f);
GameRegistry.registerBlock(this, ItemBlockBasicTile.class, "blockDecayablesChest");
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
}
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
*/
@Override
public boolean isOpaqueCube() {
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
*/
@Override
public boolean renderAsNormalBlock() {
return false;
}
/**
* The type of render function that is called for this block
*/
@Override
@SideOnly(Side.CLIENT)
public int getRenderType() {
try {
if (RenderDecayChest.INSTANCE != null) {
return RenderDecayChest.INSTANCE.mRenderID;
}
return super.getRenderType();
} catch (NullPointerException n) {
return 0;
}
}
/**
* Updates the blocks bounds based on its current state.
*/
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
if (world.getBlock(x, y, z - 1) == this) {
this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F);
} else if (world.getBlock(x, y, z + 1) == this) {
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F);
} else if (world.getBlock(x - 1, y, z) == this) {
this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
} else if (world.getBlock(x + 1, y, z) == this) {
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F);
} else {
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
}
}
/**
* Gets the block's texture. Args: side, meta
*/
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(final int ordinalSide, final int meta) {
return switch (ordinalSide) {
case 0 -> textureBottom;
case 1 -> textureTop;
default -> textureSide;
};
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(final IIconRegister p_149651_1_) {
this.blockIcon = p_149651_1_.registerIcon(GTPlusPlus.ID + ":TileEntities/DecayablesChest_top");
this.textureTop = p_149651_1_.registerIcon(GTPlusPlus.ID + ":TileEntities/DecayablesChest_top");
this.textureBottom = p_149651_1_.registerIcon(GTPlusPlus.ID + ":TileEntities/DecayablesChest_bottom");
this.textureSide = p_149651_1_.registerIcon(GTPlusPlus.ID + ":TileEntities/DecayablesChest_Side");
}
@Override
public boolean onBlockActivated(final World world, final int x, final int y, final int z, final EntityPlayer player,
final int side, final float lx, final float ly, final float lz) {
if (world.isRemote || player == null || player.worldObj != world) {
return true;
}
final TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityDecayablesChest) {
GuiFactories.tileEntity()
.open(player, x, y, z);
return true;
}
return false;
}
@Override
public int getRenderBlockPass() {
return 1;
}
@Override
public TileEntity createNewTileEntity(final World world, final int p_149915_2_) {
return new TileEntityDecayablesChest();
}
@Override
public void breakBlock(final World world, final int x, final int y, final int z, final Block block,
final int number) {
InventoryUtils.dropInventoryItems(world, x, y, z, block);
super.breakBlock(world, x, y, z, block, number);
}
@Override
public void onBlockPlacedBy(final World world, final int x, final int y, final int z, final EntityLivingBase entity,
final ItemStack stack) {
if (stack.hasDisplayName()) {
((TileEntityDecayablesChest) world.getTileEntity(x, y, z)).setCustomName(stack.getDisplayName());
}
}
@Override
public boolean canCreatureSpawn(final EnumCreatureType type, final IBlockAccess world, final int x, final int y,
final int z) {
return false;
}
}
|