melting_santa.png

This commit is contained in:
Bob 2025-05-15 22:55:59 +02:00
parent d71b0bd2c5
commit 6765d7ad79
2 changed files with 83 additions and 24 deletions

View File

@ -2,12 +2,14 @@ package com.hbm.blocks.generic;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.lwjgl.input.Keyboard;
import com.hbm.blocks.IBlockSideRotation;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ModBlocks;
import com.hbm.handler.ThreeInts;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.items.ModItems;
import com.hbm.lib.RefStrings;
@ -18,8 +20,11 @@ import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityLoadedBase;
import com.hbm.util.BufferUtil;
import com.hbm.util.I18nUtil;
import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.world.gen.INBTTransformable;
import com.hbm.world.gen.NBTStructure;
import com.hbm.world.gen.NBTStructure.Component;
import com.hbm.world.gen.NBTStructure.JigsawConnection;
import com.hbm.world.gen.NBTStructure.JigsawPiece;
import com.hbm.world.gen.NBTStructure.JigsawPool;
@ -50,6 +55,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
import net.minecraftforge.common.util.ForgeDirection;
/**
* You're familiar with Billy Mitchell, World Video Game Champion? He could probably do it.
@ -217,6 +223,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
List<String> text = new ArrayList<String>();
text.add(EnumChatFormatting.GRAY + "Target pool: " + EnumChatFormatting.RESET + jigsaw.pool);
text.add(EnumChatFormatting.GRAY + "Target name: " + EnumChatFormatting.RESET + jigsaw.target);
text.add(EnumChatFormatting.GRAY + "Turns into: " + EnumChatFormatting.RESET + GameRegistry.findUniqueIdentifierFor(jigsaw.replaceBlock).toString());
text.add(EnumChatFormatting.GRAY + " with meta: " + EnumChatFormatting.RESET + jigsaw.replaceMeta);
@ -228,6 +235,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
public static class TileEntityWandTandem extends TileEntityLoadedBase implements IControlReceiver {
private String pool = "default";
private String target = "default";
private Block replaceBlock = Blocks.air;
private int replaceMeta = 0;
@ -245,23 +253,61 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
}
private void tryGenerate() {
if(!this.isArmed || target == null || target.isEmpty()) return;
JigsawPool pool = NBTStructure.tandemSharedJiggies.get(target);
if(this.isArmed || target == null || target.isEmpty() || pool == null || pool.isEmpty()) return;
JigsawPool pool = NBTStructure.tandemSharedJiggies.get(this.pool);
if(pool == null) return;
JigsawPiece nextPiece = pool.get(worldObj.rand);
if(nextPiece == null) return;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
//JigsawConnection fromConnection = new JigsawConnection(new ThreeInts(xCoord, yCoord, zCoord), dir, this.pool, target, false, 0, 0);
JigsawConnection fromConnection = new JigsawConnection(new ThreeInts(0, 0, 0 /* ??? */), dir, this.pool, target, false, 0, 0);
//death
/*int ox = nextPiece.structure.rotateX(toConnection.pos.x, toConnection.pos.z, nextCoordBase);
List<JigsawConnection> connectionPool = getConnectionPool(nextPiece, fromConnection);
if(connectionPool == null) return;
JigsawConnection toConnection = connectionPool.get(worldObj.rand.nextInt(connectionPool.size()));
int nextCoordBase = directionOffsetToCoordBase(fromConnection.dir.getOpposite(), toConnection.dir);
BlockPos pos = getConnectionTargetPosition(fromConnection.dir.getOpposite(), nextPiece, fromConnection, nextCoordBase);
int ox = nextPiece.structure.rotateX(toConnection.pos.x, toConnection.pos.z, nextCoordBase);
int oy = toConnection.pos.y;
int oz = nextPiece.structure.rotateZ(toConnection.pos.x, toConnection.pos.z, nextCoordBase);
nextPiece.structure.build(world, x, y, z, coordBaseMode);*/
System.out.println((pos.getX() - ox) + " " + (pos.getY() - oy) + " " + (pos.getZ() - oz));
nextPiece.structure.build(worldObj, pos.getX() - ox, pos.getY() - oy, pos.getZ() - oz, nextCoordBase);
worldObj.setBlock(xCoord, yCoord, zCoord, replaceBlock, replaceMeta, 2);
}
private BlockPos getConnectionTargetPosition(ForgeDirection extendDir, JigsawPiece piece, JigsawConnection connection, int coordBaseMode) {
int x = xCoord + piece.structure.rotateX(connection.pos.x, connection.pos.z, coordBaseMode) + extendDir.offsetX;
int y = yCoord + connection.pos.y + extendDir.offsetY;
int z = zCoord + piece.structure.rotateZ(connection.pos.x, connection.pos.z, coordBaseMode) + extendDir.offsetZ;
return new BlockPos(x, y, z);
}
private int directionOffsetToCoordBase(ForgeDirection from, ForgeDirection to) {
for(int i = 0; i < 4; i++) {
if(from == to) return i % 4;
from = from.getRotation(ForgeDirection.DOWN);
}
return 0;
}
private List<JigsawConnection> getConnectionPool(JigsawPiece nextPiece, JigsawConnection fromConnection) {
if(fromConnection.dir == ForgeDirection.DOWN) {
return nextPiece.structure.toTopConnections.get(fromConnection.targetName);
} else if(fromConnection.dir == ForgeDirection.UP) {
return nextPiece.structure.toBottomConnections.get(fromConnection.targetName);
}
return nextPiece.structure.toHorizontalConnections.get(fromConnection.targetName);
}
@Override
public void serialize(ByteBuf buf) {
BufferUtil.writeString(buf, pool);
BufferUtil.writeString(buf, target);
buf.writeInt(Block.getIdFromBlock(replaceBlock));
buf.writeInt(replaceMeta);
@ -270,6 +316,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
@Override
public void deserialize(ByteBuf buf) {
pool = BufferUtil.readString(buf);
target = BufferUtil.readString(buf);
replaceBlock = Block.getBlockById(buf.readInt());
replaceMeta = buf.readInt();
@ -284,6 +331,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
nbt.setBoolean("isArmed", isArmed);
}
nbt.setString("pool", pool);
nbt.setString("target", target);
nbt.setString("block", GameRegistry.findUniqueIdentifierFor(replaceBlock).toString());
nbt.setInteger("meta", replaceMeta);
@ -297,6 +345,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
isArmed = nbt.getBoolean("isArmed");
}
pool = nbt.getString("pool");
target = nbt.getString("target");
replaceBlock = Block.getBlockFromName(nbt.getString("block"));
replaceMeta = nbt.getInteger("meta");
@ -319,6 +368,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
private final TileEntityWandTandem jigsaw;
private GuiTextField textPool;
private GuiTextField textTarget;
private GuiButton jointToggle;
@ -331,6 +381,9 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
public void initGui() {
Keyboard.enableRepeatEvents(true);
textPool = new GuiTextField(fontRendererObj, this.width / 2 - 150, 50, 300, 20);
textPool.setText(jigsaw.pool);
textTarget = new GuiTextField(fontRendererObj, this.width / 2 + 10, 100, 140, 20);
textTarget.setText(jigsaw.target);
@ -341,6 +394,9 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
drawString(fontRendererObj, "Target pool:", this.width / 2 - 150, 37, 0xA0A0A0);
textPool.drawTextBox();
drawString(fontRendererObj, "Target name:", this.width / 2 + 10, 87, 0xA0A0A0);
textTarget.drawTextBox();
@ -357,6 +413,7 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
NBTTagCompound data = new NBTTagCompound();
jigsaw.writeToNBT(data);
data.setString("pool", textPool.getText());
data.setString("target", textTarget.getText());
data.setBoolean("roll", jointToggle.displayString == "Rollable");
@ -366,12 +423,14 @@ public class BlockWandTandem extends BlockContainer implements IBlockSideRotatio
@Override
protected void keyTyped(char typedChar, int keyCode) {
super.keyTyped(typedChar, keyCode);
textPool.textboxKeyTyped(typedChar, keyCode);
textTarget.textboxKeyTyped(typedChar, keyCode);
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
textPool.mouseClicked(mouseX, mouseY, mouseButton);
textTarget.mouseClicked(mouseX, mouseY, mouseButton);
if(jointToggle.mousePressed(mc, mouseX, mouseY)) {

View File

@ -72,10 +72,10 @@ public class NBTStructure {
private List<Pair<Short, String>> itemPalette;
private BlockState[][][] blockArray;
private List<List<JigsawConnection>> fromConnections;
private Map<String, List<JigsawConnection>> toTopConnections;
private Map<String, List<JigsawConnection>> toBottomConnections;
private Map<String, List<JigsawConnection>> toHorizontalConnections;
public List<List<JigsawConnection>> fromConnections;
public Map<String, List<JigsawConnection>> toTopConnections;
public Map<String, List<JigsawConnection>> toBottomConnections;
public Map<String, List<JigsawConnection>> toHorizontalConnections;
public NBTStructure(ResourceLocation resource) {
// Can't use regular resource loading, servers don't know how!
@ -596,7 +596,7 @@ public class NBTStructure {
return definition.meta;
}
private int rotateX(int x, int z, int coordBaseMode) {
public int rotateX(int x, int z, int coordBaseMode) {
switch(coordBaseMode) {
case 1: return size.z - 1 - z;
case 2: return size.x - 1 - x;
@ -605,7 +605,7 @@ public class NBTStructure {
}
}
private int rotateZ(int x, int z, int coordBaseMode) {
public int rotateZ(int x, int z, int coordBaseMode) {
switch(coordBaseMode) {
case 1: return x;
case 2: return size.z - 1 - z;
@ -811,23 +811,23 @@ public class NBTStructure {
// Each jigsaw block in a structure will instance one of these
private static class JigsawConnection {
public static class JigsawConnection {
private final ThreeInts pos;
private final ForgeDirection dir;
public final ThreeInts pos;
public final ForgeDirection dir;
// what pool should we look through to find a connection
private final String poolName;
public final String poolName;
// when we successfully find a pool, what connections in that jigsaw piece can we target
private final String targetName;
public final String targetName;
private final boolean isRollable;
public final boolean isRollable;
private final int selectionPriority;
private final int placementPriority;
public final int selectionPriority;
public final int placementPriority;
private JigsawConnection(ThreeInts pos, ForgeDirection dir, String poolName, String targetName, boolean isRollable, int selectionPriority, int placementPriority) {
public JigsawConnection(ThreeInts pos, ForgeDirection dir, String poolName, String targetName, boolean isRollable, int selectionPriority, int placementPriority) {
this.pos = pos;
this.dir = dir;
this.poolName = poolName;
@ -930,21 +930,21 @@ public class NBTStructure {
// Overrides to fix Mojang's fucked rotations which FLIP instead of rotating in two instances
// vaer being in the mines doing this the hard way for years was absolutely not for naught
@Override
protected int getXWithOffset(int x, int z) {
public int getXWithOffset(int x, int z) {
return boundingBox.minX + piece.structure.rotateX(x, z, coordBaseMode);
}
@Override
protected int getYWithOffset(int y) {
public int getYWithOffset(int y) {
return boundingBox.minY + y;
}
@Override
protected int getZWithOffset(int x, int z) {
public int getZWithOffset(int x, int z) {
return boundingBox.minZ + piece.structure.rotateZ(x, z, coordBaseMode);
}
private ForgeDirection rotateDir(ForgeDirection dir) {
public ForgeDirection rotateDir(ForgeDirection dir) {
if(dir == ForgeDirection.UP || dir == ForgeDirection.DOWN) return dir;
switch(coordBaseMode) {
default: return dir;