Skip to content

Commit c7462d5

Browse files
Some cleanup
1 parent 8ea5560 commit c7462d5

49 files changed

Lines changed: 519 additions & 930 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 10 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import java.util.*;
44

55
import net.minecraft.block.Block;
6-
import net.minecraft.block.material.Material;
76
import net.minecraft.entity.player.EntityPlayer;
87
import net.minecraft.entity.player.InventoryPlayer;
98
import net.minecraft.item.*;
109
import net.minecraft.launchwrapper.Launch;
1110
import net.minecraft.nbt.NBTTagCompound;
1211
import net.minecraft.stats.StatList;
13-
import net.minecraft.util.MathHelper;
14-
import net.minecraft.util.MovingObjectPosition;
1512
import net.minecraft.util.StatCollector;
1613
import net.minecraft.world.World;
1714
import net.minecraft.world.biome.BiomeGenBase;
@@ -21,7 +18,7 @@
2118
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
2219
import net.minecraftforge.fluids.*;
2320
import net.minecraftforge.oredict.OreDictionary;
24-
import net.pufferlab.primal.blocks.*;
21+
import net.pufferlab.primal.blocks.BlockContainerPrimal;
2522
import net.pufferlab.primal.utils.*;
2623
import net.pufferlab.primal.world.GlobalTickingData;
2724

@@ -113,157 +110,6 @@ public static Random getSeededRandom(Random random, int x, int y, int z) {
113110
return random;
114111
}
115112

116-
public static int getBlockX(int side, int x) {
117-
if (side == 4) {
118-
x--;
119-
}
120-
if (side == 5) {
121-
x++;
122-
}
123-
return x;
124-
}
125-
126-
public static int getBlockY(int side, int y) {
127-
if (side == 0) {
128-
y--;
129-
}
130-
if (side == 1) {
131-
y++;
132-
}
133-
return y;
134-
}
135-
136-
public static int getBlockZ(int side, int z) {
137-
if (side == 2) {
138-
z--;
139-
}
140-
if (side == 3) {
141-
z++;
142-
}
143-
return z;
144-
}
145-
146-
public static boolean hasSolidWallsTop(World world, int x, int y, int z) {
147-
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
148-
Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
149-
boolean isSolid = block
150-
.isSideSolid(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir.getOpposite())
151-
|| (block instanceof BlockPile)
152-
|| (block.getMaterial() == Material.fire);
153-
if (!isSolid) {
154-
return false;
155-
}
156-
157-
}
158-
return true;
159-
}
160-
161-
public static boolean hasSolidWalls(World world, int x, int y, int z) {
162-
for (ForgeDirection dir : ItemUtils.sideDirections) {
163-
Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
164-
if (!block.isSideSolid(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir.getOpposite())) {
165-
return false;
166-
}
167-
}
168-
return true;
169-
}
170-
171-
public static Block getBlockDirection(World world, int x, int y, int z, ForgeDirection... directions) {
172-
int offsetX = x;
173-
int offsetY = y;
174-
int offsetZ = z;
175-
for (ForgeDirection direction : directions) {
176-
offsetX += direction.offsetX;
177-
offsetY += direction.offsetY;
178-
offsetZ += direction.offsetZ;
179-
}
180-
return world.getBlock(offsetX, offsetY, offsetZ);
181-
}
182-
183-
public static boolean setBlockDirection(World world, int x, int y, int z, Block block, int meta,
184-
ForgeDirection... directions) {
185-
int offsetX = x;
186-
int offsetY = y;
187-
int offsetZ = z;
188-
for (ForgeDirection direction : directions) {
189-
offsetX += direction.offsetX;
190-
offsetY += direction.offsetY;
191-
offsetZ += direction.offsetZ;
192-
}
193-
return world.setBlock(offsetX, offsetY, offsetZ, block, meta, 2);
194-
}
195-
196-
public static ForgeDirection getDirectionFromFacing(int facingMeta) {
197-
return switch (facingMeta) {
198-
case 1 -> ForgeDirection.SOUTH;
199-
case 2 -> ForgeDirection.EAST;
200-
case 3 -> ForgeDirection.NORTH;
201-
case 4 -> ForgeDirection.WEST;
202-
default -> ForgeDirection.UNKNOWN;
203-
};
204-
}
205-
206-
public static int getFacingMeta(int side, int axis) {
207-
if (axis == 0) {
208-
return switch (side) {
209-
case 3 -> 1;
210-
case 4 -> 4;
211-
case 2 -> 3;
212-
case 5 -> 2;
213-
default -> 0;
214-
};
215-
}
216-
if (axis == 1) {
217-
return switch (side) {
218-
case 0 -> 1;
219-
case 4 -> 4;
220-
case 1 -> 3;
221-
case 5 -> 2;
222-
default -> 0;
223-
};
224-
}
225-
if (axis == 2) {
226-
return switch (side) {
227-
case 3 -> 1;
228-
case 1 -> 4;
229-
case 2 -> 3;
230-
case 0 -> 2;
231-
default -> 0;
232-
};
233-
}
234-
return 0;
235-
}
236-
237-
public static int getSimpleAxisFromFacing(int facingMeta) {
238-
return switch (facingMeta) {
239-
case 1, 3 -> 1;
240-
case 2, 4 -> 2;
241-
default -> 0;
242-
};
243-
}
244-
245-
public static int getAxis(int side) {
246-
if (side == 0 || side == 1) {
247-
return 0;
248-
} else if (side == 2 || side == 3) {
249-
return 1;
250-
} else if (side == 4 || side == 5) {
251-
return 2;
252-
}
253-
return 0;
254-
}
255-
256-
public static boolean isSidePositive(int side) {
257-
if (side == 1 || side == 3 || side == 5) {
258-
return true;
259-
}
260-
return false;
261-
}
262-
263-
public static boolean isSimpleAxisConnected(int facingMeta, int facingMeta2) {
264-
return getSimpleAxisFromFacing(facingMeta) == getSimpleAxisFromFacing(facingMeta2);
265-
}
266-
267113
public static boolean equalsStack(ItemStack wild, ItemStack check) {
268114
if (wild == null || check == null) {
269115
return check == wild;
@@ -294,37 +140,16 @@ public static boolean equalsStack(ItemStack check, FluidStack wild) {
294140
return wild.getFluid() == stack.getFluid();
295141
}
296142

297-
public static MovingObjectPosition getMovingObjectPositionFromPlayer(World worldIn, EntityPlayer playerIn,
298-
boolean useLiquids) {
299-
return ItemDummy.instance.getMovingObjectPositionFromPlayerPublic(worldIn, playerIn, useLiquids);
300-
}
301-
302-
public static int getDirectionXZYaw(int yaw) {
303-
if (yaw == 0) {
304-
return 1;
305-
} else if (yaw == 1) {
306-
return 4;
307-
} else if (yaw == 2) {
308-
return 3;
309-
} else if (yaw == 3) {
310-
return 2;
311-
}
312-
313-
return 0;
314-
}
315-
316-
public static int getMetaYaw(float rotationYaw) {
317-
int yaw = MathHelper.floor_double((double) (rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
318-
return getDirectionXZYaw(yaw);
319-
}
320-
321143
public static void place(ItemStack stack, World world, int x, int y, int z, Block toPlace, int metadata,
322144
EntityPlayer player) {
323145
if (world.isAirBlock(x, y, z) && world.isSideSolid(x, y - 1, z, ForgeDirection.UP)) {
324146
if (world.checkNoEntityCollision(toPlace.getCollisionBoundingBoxFromPool(world, x, y, z))
325147
&& world.setBlock(x, y, z, toPlace, metadata, 3)) {
326148
world.setBlock(x, y, z, toPlace, metadata, 2);
327149
toPlace.onBlockPlacedBy(world, x, y, z, player, stack);
150+
if (toPlace instanceof BlockContainerPrimal block2) {
151+
block2.onBlockSidePlacedBy(world, x, y, z, player, stack, 0);
152+
}
328153
stack.stackSize -= 1;
329154
playSound(world, x, y, z, toPlace);
330155
player.swingItem();
@@ -339,6 +164,9 @@ public static void placeNoConsume(ItemStack stack, World world, int x, int y, in
339164
&& world.setBlock(x, y, z, toPlace, metadata, 3)) {
340165
world.setBlock(x, y, z, toPlace, metadata, 2);
341166
toPlace.onBlockPlacedBy(world, x, y, z, player, stack);
167+
if (toPlace instanceof BlockContainerPrimal block2) {
168+
block2.onBlockSidePlacedBy(world, x, y, z, player, stack, 0);
169+
}
342170
playSound(world, x, y, z, toPlace);
343171
player.swingItem();
344172
}
@@ -352,6 +180,9 @@ public static void placeSilent(ItemStack stack, World world, int x, int y, int z
352180
&& world.setBlock(x, y, z, toPlace, metadata, 3)) {
353181
world.setBlock(x, y, z, toPlace, metadata, 2);
354182
toPlace.onBlockPlacedBy(world, x, y, z, player, stack);
183+
if (toPlace instanceof BlockContainerPrimal block2) {
184+
block2.onBlockSidePlacedBy(world, x, y, z, player, stack, 0);
185+
}
355186
player.swingItem();
356187
}
357188
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import net.minecraft.util.IIcon;
1313
import net.minecraft.world.World;
1414
import net.pufferlab.primal.Primal;
15-
import net.pufferlab.primal.Utils;
1615
import net.pufferlab.primal.items.itemblocks.ItemBlockAxle;
1716
import net.pufferlab.primal.tileentities.TileEntityAxle;
17+
import net.pufferlab.primal.utils.FacingUtils;
1818

1919
public class BlockAxle extends BlockMotion {
2020

@@ -37,7 +37,7 @@ public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer
3737
if (heldItem == null) return false;
3838
if (heldItem.getItem() == Item.getItemFromBlock(this) && heldItem.getItemDamage() == 1) {
3939
int axis = tef.axisMeta;
40-
int axisClicked = Utils.getAxis(side);
40+
int axisClicked = FacingUtils.getAxis(side);
4141
if (axis == axisClicked) {
4242
tef.setGear(side, player);
4343
return true;

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

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package net.pufferlab.primal.blocks;
22

33
import java.util.List;
4-
import java.util.Random;
54

65
import net.minecraft.block.material.Material;
76
import net.minecraft.client.renderer.texture.IIconRegister;
87
import net.minecraft.entity.Entity;
98
import net.minecraft.entity.EntityLivingBase;
10-
import net.minecraft.entity.item.EntityItem;
119
import net.minecraft.entity.player.EntityPlayer;
1210
import net.minecraft.item.ItemStack;
1311
import net.minecraft.nbt.NBTTagCompound;
@@ -18,10 +16,9 @@
1816
import net.minecraft.world.World;
1917
import net.minecraftforge.common.util.ForgeDirection;
2018
import net.pufferlab.primal.Primal;
21-
import net.pufferlab.primal.Utils;
2219
import net.pufferlab.primal.recipes.BarrelRecipe;
2320
import net.pufferlab.primal.tileentities.TileEntityBarrel;
24-
import net.pufferlab.primal.tileentities.TileEntityInventory;
21+
import net.pufferlab.primal.utils.FacingUtils;
2522

2623
public class BlockBarrel extends BlockContainerPrimal {
2724

@@ -88,29 +85,6 @@ public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer
8885
return true;
8986
}
9087

91-
private void dropItems(World world, int i, int j, int k) {
92-
Random rando = world.rand;
93-
TileEntity tileEntity = world.getTileEntity(i, j, k);
94-
if (!(tileEntity instanceof TileEntityInventory)) return;
95-
TileEntityInventory inventory = (TileEntityInventory) tileEntity;
96-
for (int x = 0; x < inventory.getSizeInventory(); x++) {
97-
ItemStack item = inventory.getStackInSlot(x);
98-
inventory.setInventorySlotContentsUpdate(x, null);
99-
if (item != null && item.stackSize > 0) {
100-
float ri = rando.nextFloat() * 0.8F + 0.1F;
101-
float rj = rando.nextFloat() * 0.8F + 0.1F;
102-
float rk = rando.nextFloat() * 0.8F + 0.1F;
103-
EntityItem entityItem = new EntityItem(world, (i + ri), (j + rj + 0.7F), (k + rk), item.copy());
104-
float factor = 0.05F;
105-
entityItem.motionX = rando.nextGaussian() * factor;
106-
entityItem.motionY = rando.nextGaussian() * factor + 0.20000000298023224D;
107-
entityItem.motionZ = rando.nextGaussian() * factor;
108-
spawnEntity(world, entityItem);
109-
item.stackSize = 0;
110-
}
111-
}
112-
}
113-
11488
@Override
11589
public void registerBlockIcons(IIconRegister reg) {
11690
icons[0] = reg.registerIcon(Primal.MODID + ":barrel");
@@ -141,7 +115,12 @@ public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase
141115
}
142116
}
143117

144-
int metayaw = Utils.getMetaYaw(placer.rotationYaw);
118+
}
119+
120+
@Override
121+
public void onBlockSidePlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn,
122+
int side) {
123+
int metayaw = FacingUtils.getMetaYawSide(placer.rotationYaw, side);
145124
TileEntity te = worldIn.getTileEntity(x, y, z);
146125
if (te instanceof TileEntityBarrel tef) {
147126
tef.setFacingMeta(metayaw);
@@ -151,7 +130,6 @@ public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase
151130
tef.setFloorBarrel(false);
152131
}
153132
}
154-
155133
}
156134

157135
@Override
@@ -173,23 +151,6 @@ public void onBlockPreDestroy(World worldIn, int x, int y, int z, int meta) {
173151
@Override
174152
protected void dropBlockAsItem(World worldIn, int x, int y, int z, ItemStack itemIn) {}
175153

176-
public void dropItemStack(World world, int x, int y, int z, ItemStack item) {
177-
if (item != null && item.stackSize > 0) {
178-
EntityItem entityItem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, item.copy());
179-
entityItem.motionX = 0.0D;
180-
entityItem.motionY = 0.0D;
181-
entityItem.motionZ = 0.0D;
182-
spawnEntity(world, entityItem);
183-
item.stackSize = 0;
184-
}
185-
}
186-
187-
public void spawnEntity(World world, Entity entityItem) {
188-
if (!world.isRemote) {
189-
world.spawnEntityInWorld((Entity) entityItem);
190-
}
191-
}
192-
193154
@Override
194155
public TileEntity createNewTileEntity(World worldIn, int meta) {
195156
return new TileEntityBarrel();

0 commit comments

Comments
 (0)