Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalable Walrus #248

Merged
merged 7 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.lwjgl.opengl.GL11;

import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.tile.TileWalrus;

public class RenderBlockWalrus extends TileEntitySpecialRenderer {

Expand All @@ -19,16 +20,28 @@ public class RenderBlockWalrus extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTickTime) {
Minecraft.getMinecraft().renderEngine.bindTexture(this.textureWalrus);
if (!(tileentity instanceof TileWalrus Tile)) return;
float scale = Tile.getWalrusScale();
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y, z + 0.5);
int orientation = tileentity.getBlockMetadata();
if (orientation == 4) {
GL11.glRotatef(90, 0, 1, 0);
} else if (orientation == 5) {
GL11.glRotatef(-90, 0, 1, 0);
} else if (orientation == 3) {
GL11.glRotatef(180, 0, 1, 0);
int orientation = Tile.getBlockMetadata();
switch (orientation) {
case 2:
GL11.glTranslated(x + 0.5, y, z + 1 - scale * .655); // centering walrus model
break;
case 3:
GL11.glTranslated(x + 0.5, y, z + scale * .655);
GL11.glRotatef(180, 0, 1, 0);
break;
case 4:
GL11.glTranslated(x + 1 - scale * .655, y, z + 0.5);
GL11.glRotatef(90, 0, 1, 0);
break;
case 5:
GL11.glTranslated(x + scale * .655, y, z + 0.5);
GL11.glRotatef(-90, 0, 1, 0);
break;
}
GL11.glScalef(scale, scale, scale);
this.modelWalrus.renderAll();
GL11.glPopMatrix();
}
Expand Down
49 changes: 39 additions & 10 deletions src/main/java/com/glodblock/github/common/block/BlockWalrus.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase p
int l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;

if (l == 0) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}

if (l == 1) {
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}

if (l == 2) {
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}

if (l == 3) {
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
}

Expand All @@ -75,12 +75,28 @@ public boolean renderAsNormalBlock() {

@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);
}
}
}

Expand All @@ -102,4 +118,17 @@ public void addInformation(final ItemStack itemStack, final EntityPlayer player,
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;
}
}
48 changes: 46 additions & 2 deletions src/main/java/com/glodblock/github/common/tile/TileWalrus.java
Original file line number Diff line number Diff line change
@@ -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();
}
}