Scalable Walrus (#248)

Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Maya <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-01-04 15:48:13 -07:00
1 parent d8de0e8f27
commit 0b67a8a4e7
3 files changed
+111 -25

No files matched your search

@@ -52,20 +52,20 @@ public class BlockWalrus extends BaseBlockContainer {
int l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if (l == 0) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1) {
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2) {
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3) {
if (l == 1) {
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if (l == 2) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 3) {
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
}
@Override
@@ -75,12 +75,28 @@ public class BlockWalrus extends BaseBlockContainer {
@Override
public void setBlockBoundsBasedOnState(IBlockAccess blockAccess, int x, int y, int z) {
switch (ForgeDirection.getOrientation(blockAccess.getBlockMetadata(x, y, z))) {
case NORTH -> setBlockBounds(0.0F, 0.0F, -1.0F, 1.0F, 1.0F, 1.0F);
case EAST -> setBlockBounds(0.0F, 0.0F, 0.0F, 2.0F, 1.0F, 1.0F);
case SOUTH -> setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 2.0F);
case WEST -> setBlockBounds(-1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
default -> setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
TileEntity tileentity = blockAccess.getTileEntity(x, y, z);
if (tileentity instanceof TileWalrus Tile) {
float scale = Tile.getWalrusScale();
switch (ForgeDirection.getOrientation(blockAccess.getBlockMetadata(x, y, z))) {
case NORTH -> setBlockBounds(
-(scale / 2 - 0.5F),
0.0F,
-scale * 2F + 1.0F,
(scale / 2 + 0.5f),
scale,
1.0F);
case EAST -> setBlockBounds(0.0F, 0.0F, -(scale / 2 - 0.5F), 2.0F * scale, scale, (scale / 2 + 0.5f));
case SOUTH -> setBlockBounds(-(scale / 2 - 0.5F), 0.F, 0.F, (scale / 2 + 0.5f), scale, 2.0F * scale);
case WEST -> setBlockBounds(
-scale * 2F + 1.0F,
0.0F,
-(scale / 2 - 0.5F),
1.0F,
scale,
(scale / 2 + 0.5f));
default -> setBlockBounds(0.0F, 0.0F, 0.0F, scale, scale, scale);
}
}
}
@@ -102,4 +118,17 @@ public class BlockWalrus extends BaseBlockContainer {
toolTip.add(NameConst.i18n(NameConst.TT_SHIFT_FOR_MORE));
}
}
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID,
float offsetX, float offsetY, float offsetZ) {
TileEntity tileentity = worldObj.getTileEntity(x, y, z);
if (!(tileentity instanceof TileWalrus Tile)) return false;
if (entityplayer.isSneaking()) {
Tile.setWalrusScale(Tile.getWalrusScale() / 2);
} else {
Tile.setWalrusScale(Tile.getWalrusScale() * 2);
}
return true;
}
}
@@ -1,11 +1,55 @@
package com.glodblock.github.common.tile;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
public class TileWalrus extends TileEntity {
private float scale = 1f;
@Override
public boolean canUpdate() {
return false;
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
if (data.hasKey("scale")) {
scale = data.getFloat("scale");
}
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setFloat("scale", scale);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
}
@Override
public double getMaxRenderDistanceSquared() {
return 102400;
}
public float getWalrusScale() {
return scale;
}
public void setWalrusScale(float f) {
if (f > 256f) f = 256f;
if (f < 0.03f) f = 0.03f;
scale = f;
markDirty();
}
}