Skip to content

Commit 21422ef

Browse files
Added simple waterwheel + generator gui
1 parent 7688bc8 commit 21422ef

24 files changed

Lines changed: 943 additions & 80 deletions

src/main/java/net/pufferlab/primal/ClientProxy.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.pufferlab.primal.events.*;
1717
import net.pufferlab.primal.inventory.container.ContainerKnapping;
1818
import net.pufferlab.primal.inventory.gui.GuiCrucible;
19+
import net.pufferlab.primal.inventory.gui.GuiGenerator;
1920
import net.pufferlab.primal.inventory.gui.GuiKnapping;
2021
import net.pufferlab.primal.inventory.gui.GuiLargeVessel;
2122
import net.pufferlab.primal.recipes.KnappingType;
@@ -98,6 +99,7 @@ public void setupRenders() {
9899
register(TileEntityQuern.class, new TileEntityQuernRenderer());
99100
register(TileEntityAxle.class, new TileEntityAxleRenderer());
100101
register(TileEntityGenerator.class, new TileEntityGeneratorRenderer());
102+
register(TileEntityWaterWheel.class, new TileEntityWaterWheelRenderer());
101103

102104
register(Registry.wood, new ItemWoodRenderer());
103105
register(Registry.clay, new ItemClayRenderer());
@@ -113,7 +115,7 @@ public void setupRenders() {
113115
register(Registry.ceramic_bucket, new ItemBucketCeramicRenderer());
114116
register(Registry.axle, new ItemAxleRenderer());
115117
register(Registry.generator, new ItemGeneratorRenderer());
116-
register(Registry.gear, new ItemGearRenderer());
118+
register(Registry.waterwheel, new ItemWaterWheelRenderer());
117119
}
118120

119121
public int getNextId() {
@@ -154,6 +156,12 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
154156
return new GuiCrucible(player.inventory, tef);
155157
}
156158
}
159+
if (ID == generatorGuiID) {
160+
TileEntity te = world.getTileEntity(x, y, z);
161+
if (te instanceof TileEntityGenerator tef) {
162+
return new GuiGenerator(tef);
163+
}
164+
}
157165
return null;
158166
}
159167

src/main/java/net/pufferlab/primal/CommonProxy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class CommonProxy implements IGuiHandler {
2424

2525
public final int largeVesselContainerID = 0;
2626
public final int crucibleContainerID = 1;
27+
public final int generatorGuiID = 2;
2728
private int nextPacketID;
2829

2930
public void preInit(FMLPreInitializationEvent event) {

src/main/java/net/pufferlab/primal/Registry.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public String getTranslatedTabLabel() {
6161
public static final Block quern;
6262
public static final Block axle;
6363
public static final Block generator;
64-
public static final Item gear;
64+
public static final Block waterwheel;
6565
public static final Item icons;
6666
public static final Item straw;
6767
public static final Item hide;
@@ -107,14 +107,14 @@ public String getTranslatedTabLabel() {
107107

108108
axle = new BlockAxle();
109109
generator = new BlockGenerator();
110+
waterwheel = new BlockWaterWheel();
110111

111112
thatch = new BlockThatch();
112113
thatch_roof = new BlockThatchRoof();
113114
chimney = new BlockChimney();
114115

115116
icons = new ItemMeta(Constants.icons, "icon").setHiddenAll()
116117
.setHasSuffix();
117-
gear = new ItemMeta(Constants.gearItems, "gear");
118118
straw = new ItemMeta(Constants.strawItems, "straw");
119119
hide = new ItemMeta(Constants.hideItems, "hide");
120120
wood = new ItemMeta(Constants.woodItems, "wood");
@@ -163,9 +163,9 @@ public void setup() {
163163
register(tanning, "tanning_frame");
164164
register(axle, "axle");
165165
register(generator, "generator");
166+
register(waterwheel, "waterwheel");
166167

167168
register(icons, "icon");
168-
register(gear, "gear");
169169
register(straw, "straw");
170170
register(hide, "hide");
171171
register(wood, "wood");
@@ -205,6 +205,7 @@ public void setupTiles() {
205205
register(TileEntityQuern.class, "quern");
206206
register(TileEntityAxle.class, "axle");
207207
register(TileEntityGenerator.class, "generator");
208+
register(TileEntityWaterWheel.class, "waterwheel");
208209
}
209210

210211
public static final Block[] fluidsBlocks = new Block[Constants.fluidsTypes.length];
@@ -233,6 +234,8 @@ public void setupPackets() {
233234
Primal.network = NetworkRegistry.INSTANCE.newSimpleChannel(Primal.MODID);
234235
registerPacket(PacketKnappingClick.class, Side.SERVER);
235236
registerPacket(PacketPitKilnPlace.class, Side.SERVER);
237+
registerPacket(PacketSpeedChange.class, Side.SERVER);
238+
236239
registerPacket(PacketSwingArm.class, Side.CLIENT);
237240
registerPacket(PacketFireStarter.class, Side.CLIENT);
238241
registerPacket(PacketSpeedUpdate.class, Side.CLIENT);
@@ -291,6 +294,10 @@ public void register(Block block, String name) {
291294
GameRegistry.registerBlock(block.setCreativeTab(Registry.creativeTab), ItemBlockMeta.class, name);
292295
} else if (block instanceof BlockCrucible) {
293296
GameRegistry.registerBlock(block.setCreativeTab(Registry.creativeTab), ItemBlockHeatable.class, name);
297+
} else if (block instanceof BlockAxle) {
298+
GameRegistry.registerBlock(block.setCreativeTab(Registry.creativeTab), ItemBlockAxle.class, name);
299+
} else if (block instanceof BlockWaterWheel) {
300+
GameRegistry.registerBlock(block.setCreativeTab(Registry.creativeTab), ItemBlockWaterWheel.class, name);
294301
} else if (block instanceof BlockMotion) {
295302
GameRegistry.registerBlock(block.setCreativeTab(Registry.creativeTab), ItemBlockMotion.class, name);
296303
} else {

src/main/java/net/pufferlab/primal/blocks/BlockAxle.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
package net.pufferlab.primal.blocks;
22

33
import net.minecraft.block.material.Material;
4+
import net.minecraft.client.renderer.texture.IIconRegister;
45
import net.minecraft.entity.Entity;
56
import net.minecraft.entity.item.EntityItem;
67
import net.minecraft.entity.player.EntityPlayer;
78
import net.minecraft.item.ItemStack;
89
import net.minecraft.tileentity.TileEntity;
10+
import net.minecraft.util.IIcon;
911
import net.minecraft.world.World;
1012
import net.pufferlab.primal.Primal;
1113
import net.pufferlab.primal.Utils;
1214
import net.pufferlab.primal.tileentities.TileEntityAxle;
1315

1416
public class BlockAxle extends BlockMotion {
1517

18+
public IIcon[] icons = new IIcon[1];
19+
1620
public BlockAxle() {
1721
super(Material.wood);
22+
this.setHardness(2.0F);
23+
this.setStepSound(soundTypeWood);
1824
}
1925

2026
@Override
@@ -50,7 +56,7 @@ public void onBlockPreDestroy(World worldIn, int x, int y, int z, int meta) {
5056
numberGear++;
5157
}
5258
if (numberGear > 0) {
53-
dropItemStack(worldIn, x, y, z, Utils.getModItem("gear", numberGear));
59+
dropItemStack(worldIn, x, y, z, new ItemStack(this, 1, 1));
5460
}
5561
}
5662
}
@@ -72,6 +78,16 @@ public void spawnEntity(World world, Entity entityItem) {
7278
}
7379
}
7480

81+
@Override
82+
public void registerBlockIcons(IIconRegister reg) {
83+
icons[0] = reg.registerIcon("minecraft:planks_spruce");
84+
}
85+
86+
@Override
87+
public IIcon getIcon(int side, int meta) {
88+
return icons[0];
89+
}
90+
7591
@Override
7692
public TileEntity createNewTileEntity(World worldIn, int meta) {
7793
return new TileEntityAxle();

src/main/java/net/pufferlab/primal/blocks/BlockGenerator.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.block.material.Material;
44
import net.minecraft.client.renderer.texture.IIconRegister;
5+
import net.minecraft.entity.player.EntityPlayer;
56
import net.minecraft.tileentity.TileEntity;
67
import net.minecraft.util.IIcon;
78
import net.minecraft.world.World;
@@ -10,23 +11,37 @@
1011

1112
public class BlockGenerator extends BlockMotion {
1213

13-
public IIcon[] icons = new IIcon[1];
14+
public IIcon[] icons = new IIcon[2];
1415

1516
public BlockGenerator() {
1617
super(Material.wood);
18+
this.setHardness(2.0F);
19+
this.setStepSound(soundTypeWood);
20+
}
21+
22+
@Override
23+
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX,
24+
float subY, float subZ) {
25+
if (player.isSneaking() && worldIn.isRemote) {
26+
player.openGui(Primal.instance, Primal.proxy.generatorGuiID, worldIn, x, y, z);
27+
return true;
28+
}
29+
30+
return false;
1731
}
1832

1933
@Override
2034
public void registerBlockIcons(IIconRegister reg) {
21-
icons[0] = reg.registerIcon(Primal.MODID + ":generator");
35+
icons[0] = reg.registerIcon("minecraft:planks_spruce");
36+
icons[1] = reg.registerIcon(Primal.MODID + ":generator");
2237
}
2338

2439
@Override
2540
public IIcon getIcon(int side, int meta) {
2641
if (side == 99) {
27-
return icons[0];
42+
return icons[1];
2843
}
29-
return null;
44+
return icons[0];
3045
}
3146

3247
@Override
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package net.pufferlab.primal.blocks;
2+
3+
import net.minecraft.block.Block;
4+
import net.minecraft.block.material.Material;
5+
import net.minecraft.client.renderer.texture.IIconRegister;
6+
import net.minecraft.tileentity.TileEntity;
7+
import net.minecraft.util.IIcon;
8+
import net.minecraft.world.World;
9+
import net.minecraftforge.common.util.ForgeDirection;
10+
import net.pufferlab.primal.Primal;
11+
import net.pufferlab.primal.Utils;
12+
import net.pufferlab.primal.tileentities.TileEntityWaterWheel;
13+
14+
public class BlockWaterWheel extends BlockMotion {
15+
16+
public IIcon[] icons = new IIcon[1];
17+
18+
public BlockWaterWheel() {
19+
super(Material.wood);
20+
this.setHardness(2.0F);
21+
this.setStepSound(soundTypeWood);
22+
}
23+
24+
@Override
25+
public void onNeighborBlockChange(World worldIn, int x, int y, int z, Block neighbor) {
26+
TileEntity te = worldIn.getTileEntity(x, y, z);
27+
if (te instanceof TileEntityWaterWheel tef) {
28+
if (tef.isExtension) {
29+
TileEntity te2 = worldIn.getTileEntity(tef.baseXCoord, tef.baseYCoord, tef.baseZCoord);
30+
if (te2 instanceof TileEntityWaterWheel tef2) {
31+
tef2.scheduleFlowUpdate();
32+
}
33+
} else {
34+
tef.scheduleFlowUpdate();
35+
}
36+
}
37+
}
38+
39+
@Override
40+
public void onBlockDestroyedByPlayer(World worldIn, int x, int y, int z, int meta) {
41+
super.onBlockDestroyedByPlayer(worldIn, x, y, z, meta);
42+
}
43+
44+
@Override
45+
public void onBlockPreDestroy(World worldIn, int x, int y, int z, int meta) {
46+
super.onBlockPreDestroy(worldIn, x, y, z, meta);
47+
48+
TileEntity te = worldIn.getTileEntity(x, y, z);
49+
if (te instanceof TileEntityWaterWheel tef) {
50+
if (!tef.needsRemove) {
51+
if (tef.isExtension) {
52+
clearExtensions(worldIn, tef.baseXCoord, tef.baseYCoord, tef.baseZCoord, tef.axisMeta);
53+
TileEntity te2 = worldIn.getTileEntity(tef.baseXCoord, tef.baseYCoord, tef.baseZCoord);
54+
if (te2 instanceof TileEntityWaterWheel tef2) {
55+
tef2.needsRemove = true;
56+
}
57+
} else {
58+
clearExtensions(worldIn, tef.xCoord, tef.yCoord, tef.zCoord, tef.axisMeta);
59+
}
60+
}
61+
}
62+
}
63+
64+
public void clearExtensions(World worldObj, int x, int y, int z, int axis) {
65+
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
66+
for (ForgeDirection direction0 : ForgeDirection.VALID_DIRECTIONS) {
67+
if (Utils.getAxis(direction.ordinal()) != axis && Utils.getAxis(direction0.ordinal()) != axis) {
68+
for (ForgeDirection direction2 : ForgeDirection.VALID_DIRECTIONS) {
69+
if (direction2 != direction && direction2 != direction.getOpposite()
70+
&& Utils.getAxis(direction2.ordinal()) != axis) {
71+
int x2 = x + direction.offsetX + direction2.offsetX;
72+
int y2 = y + direction.offsetY + direction2.offsetY;
73+
int z2 = z + direction.offsetZ + direction2.offsetZ;
74+
if (direction2 == direction0) {
75+
x2 = x + direction.offsetX;
76+
y2 = y + direction.offsetY;
77+
z2 = z + direction.offsetZ;
78+
}
79+
TileEntity te = worldObj.getTileEntity(x2, y2, z2);
80+
if (te instanceof TileEntityWaterWheel tef) {
81+
tef.needsRemove = true;
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
89+
90+
@Override
91+
public void registerBlockIcons(IIconRegister reg) {
92+
icons[0] = reg.registerIcon("minecraft:planks_spruce");
93+
}
94+
95+
@Override
96+
public IIcon getIcon(int side, int meta) {
97+
return icons[0];
98+
}
99+
100+
@Override
101+
public TileEntity createNewTileEntity(World worldIn, int meta) {
102+
return new TileEntityWaterWheel();
103+
}
104+
105+
@Override
106+
public String getUnlocalizedName() {
107+
return "tile." + Primal.MODID + ".waterwheel";
108+
}
109+
110+
@Override
111+
public int getRenderType() {
112+
return Primal.proxy.getAxleRenderID();
113+
}
114+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package net.pufferlab.primal.client.models;
2+
3+
import net.pufferlab.primal.client.utils.ModelRenderer;
4+
5+
public class ModelWaterWheel extends ModelPrimal {
6+
7+
public ModelRenderer ring_45;
8+
public ModelRenderer beam_90;
9+
public ModelRenderer side_30;
10+
11+
public ModelWaterWheel() {
12+
super(64);
13+
14+
beam_90 = new ModelRenderer(this);
15+
beam_90.setRotationPoint(0.0F, 0.0F, 0.0F);
16+
for (int i = 0; i < 4; i++) {
17+
ModelRenderer beam = new ModelRenderer(this);
18+
float angle = (float) Math.toRadians(90 * i);
19+
beam.setRotationPoint(0.0F, 0.0F, 0.0F);
20+
setRotationAngle(beam, 0.0F, angle, 0.0F);
21+
beam.addBox(0, 39, -22.0F, 4.0F, -2.0F, 20, 4, 4, 0.0F);
22+
beam.addBox(0, 39, -22.0F, 4.0F - 12F, -2.0F, 20, 4, 4, 0.0F);
23+
beam_90.addChild(beam);
24+
}
25+
bb_main.addChild(beam_90);
26+
27+
ring_45 = new ModelRenderer(this);
28+
ring_45.setRotationPoint(0.0F, 0.0F, 0.0F);
29+
for (int i = 0; i < 8; i++) {
30+
ModelRenderer ring = new ModelRenderer(this);
31+
float angle = (float) Math.toRadians(45 * i);
32+
ring.setRotationPoint(0.0F, 0.0F, 0.0F);
33+
setRotationAngle(ring, 0.0F, angle, 0.0F);
34+
ring.addBox(0, 31, -11.0F, -8.0F - 1F, -25.0F, 22, 4, 4, 0.0F);
35+
ring.addBox(0, 31, -11.0F, -8.0F + 12F + 1F, -25.0F, 22, 4, 4, 0.0F);
36+
ring_45.addChild(ring);
37+
}
38+
bb_main.addChild(ring_45);
39+
40+
side_30 = new ModelRenderer(this);
41+
side_30.setRotationPoint(0.0F, 0.0F, 0.0F);
42+
for (int i = 0; i < 12; i++) {
43+
ModelRenderer side = new ModelRenderer(this);
44+
float angle = (float) Math.toRadians(30 * i);
45+
side.setRotationPoint(0.0F, 0.0F, 0.0F);
46+
setRotationAngle(side, 0.0F, angle, 0.0F);
47+
side.addBox(0, 0, -24.0F, -8.0F, -7.0F, 2, 16, 14, 0.0F);
48+
side.addBox(33, 0, -33.0F, -8.0F, -2.0F, 9, 16, 2, 0.0F);
49+
side_30.addChild(side);
50+
}
51+
bb_main.addChild(side_30);
52+
}
53+
54+
@Override
55+
public String getName() {
56+
return "blocks/waterwheel";
57+
}
58+
}

0 commit comments

Comments
 (0)