Merge pull request #1208 from sdddddf80/custom-machine-structure-tool

A simple tool for generating custom machine multi block structure code
This commit is contained in:
HbmMods 2023-10-06 15:08:11 +02:00 committed by GitHub
commit 4112a11438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 224 additions and 1 deletions

View File

@ -887,6 +887,7 @@ public class ModBlocks {
public static Block cm_circuit;
public static Block cm_port;
public static Block custom_machine;
public static Block cm_anchor;
public static Block pwr_fuel;
public static Block pwr_control;
@ -2061,6 +2062,7 @@ public class ModBlocks {
cm_circuit = new BlockCM(Material.iron, EnumCMCircuit.class, true, true).setBlockName("cm_circuit").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_circuit");
cm_port = new BlockCMPort(Material.iron, EnumCMMaterials.class, true, true).setBlockName("cm_port").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_port");
custom_machine = new BlockCustomMachine().setBlockName("custom_machine").setCreativeTab(MainRegistry.machineTab).setLightLevel(1F).setHardness(5.0F).setResistance(10.0F);
cm_anchor = new BlockCMAnchor().setBlockName("custom_machine_anchor").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F);
pwr_fuel = new BlockPillarPWR(Material.iron, RefStrings.MODID + ":pwr_fuel_top").setBlockName("pwr_fuel").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":pwr_fuel_side");
pwr_control = new BlockPillarPWR(Material.iron, RefStrings.MODID + ":pwr_control_top").setBlockName("pwr_control").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":pwr_control_side");
@ -3421,6 +3423,7 @@ public class ModBlocks {
register(cm_tank);
register(cm_circuit);
register(cm_port);
register(cm_anchor);
//PWR
register(pwr_fuel);

View File

@ -0,0 +1,43 @@
package com.hbm.blocks.machine;
import com.hbm.lib.RefStrings;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class BlockCMAnchor extends Block {
@SideOnly(Side.CLIENT)
private IIcon iconFront;
public BlockCMAnchor() {
super(Material.iron);
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.iconFront = iconRegister.registerIcon(RefStrings.MODID + ":cm_terminal_front");
this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":cm_terminal_side");
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
return metadata == 0 && side == 3 ? this.iconFront : (side == metadata ? this.iconFront : this.blockIcon);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if(i == 0) world.setBlockMetadataWithNotify(x, y, z, 2, 2);
if(i == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2);
if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2);
if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
}

View File

@ -2215,6 +2215,7 @@ public class ModItems {
public static Item structure_pattern;
public static Item structure_randomized;
public static Item structure_randomly;
public static Item structure_custommachine;
public static Item rod_of_discord;
@ -4486,7 +4487,8 @@ public class ModItems {
structure_pattern = new ItemStructurePattern().setUnlocalizedName("structure_pattern").setMaxStackSize(1).setCreativeTab(null).setFull3D().setTextureName(RefStrings.MODID + ":structure_pattern");
structure_randomized = new ItemStructureRandomized().setUnlocalizedName("structure_randomized").setMaxStackSize(1).setCreativeTab(null).setFull3D().setTextureName(RefStrings.MODID + ":structure_randomized");
structure_randomly = new ItemStructureRandomly().setUnlocalizedName("structure_randomly").setMaxStackSize(1).setCreativeTab(null).setFull3D().setTextureName(RefStrings.MODID + ":structure_randomly");
structure_custommachine = new ItemCMStructure().setUnlocalizedName("structure_custommachine").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setFull3D().setTextureName(RefStrings.MODID + ":structure_custommachine");
rod_of_discord = new ItemDiscord().setUnlocalizedName("rod_of_discord").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setFull3D().setTextureName(RefStrings.MODID + ":rod_of_discord");
nuke_starter_kit = new ItemStarterKit().setUnlocalizedName("nuke_starter_kit").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":nuke_starter_kit");
@ -7948,6 +7950,7 @@ public class ModItems {
GameRegistry.registerItem(structure_pattern, structure_pattern.getUnlocalizedName());
GameRegistry.registerItem(structure_randomized, structure_randomized.getUnlocalizedName());
GameRegistry.registerItem(structure_randomly, structure_randomly.getUnlocalizedName());
GameRegistry.registerItem(structure_custommachine, structure_custommachine.getUnlocalizedName());
GameRegistry.registerItem(rod_of_discord, rod_of_discord.getUnlocalizedName());
//GameRegistry.registerItem(analyzer, analyzer.getUnlocalizedName());
//GameRegistry.registerItem(remote, remote.getUnlocalizedName());

View File

@ -0,0 +1,172 @@
package com.hbm.items.tool;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import com.google.gson.stream.JsonWriter;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ModBlocks;
import com.hbm.main.MainRegistry;
import com.hbm.util.fauxpointtwelve.BlockPos;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.util.ForgeDirection;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
public class ItemCMStructure extends Item implements ILookOverlay {
File file = new File(MainRegistry.configHbmDir, "CMstructureOutput.txt");
public static BlockPos getAnchor(ItemStack stack) {
if(!stack.hasTagCompound()) {
return null;
}
return new BlockPos(stack.stackTagCompound.getInteger("anchorX"), stack.stackTagCompound.getInteger("anchorY"), stack.stackTagCompound.getInteger("anchorZ"));
}
public static void setAnchor(ItemStack stack, int x, int y, int z) {
if(stack.stackTagCompound == null) {
stack.stackTagCompound = new NBTTagCompound();
}
stack.stackTagCompound.setInteger("anchorX", x);
stack.stackTagCompound.setInteger("anchorY", y);
stack.stackTagCompound.setInteger("anchorZ", z);
}
public static void writeToFile(File config,ItemStack stack,World world){
int anchorX = stack.stackTagCompound.getInteger("anchorX");
int anchorY = stack.stackTagCompound.getInteger("anchorY");
int anchorZ = stack.stackTagCompound.getInteger("anchorZ");
int x1=stack.stackTagCompound.getInteger("x1");
int y1=stack.stackTagCompound.getInteger("y1");
int z1=stack.stackTagCompound.getInteger("z1");
int x2=stack.stackTagCompound.getInteger("x2");
int y2=stack.stackTagCompound.getInteger("y2");
int z2=stack.stackTagCompound.getInteger("z2");
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(anchorX,anchorY,anchorZ));
//ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
int z=z1;z1=z<z2?z:z2;z2=z<z2?z2:z;
int y=y1;y1=y<y2?y:y2;y2=y<y2?y2:y;
int x=x1;x1=x<x2?x:x2;x2=x<x2?x2:x;
if(dir == ForgeDirection.EAST || dir == ForgeDirection.WEST){
z=x1;x1=z1;z1=z;
z=x2;x2=z2;z2=z;
int anchor=anchorX;anchorX=anchorZ;anchorZ=anchor;
}
try {
JsonWriter writer = new JsonWriter(new FileWriter(config));
writer.setIndent(" ");
writer.beginObject();
writer.name("components").beginArray();
for(x=x1;x<=x2;x++){
for(y=y1;y<=y2;y++){
for(z=z1;z<=z2;z++){
if(!((x==anchorX&&y==anchorY&&z==anchorZ)||((dir == ForgeDirection.EAST || dir == ForgeDirection.WEST)?world.getBlock(z, y, x)==Blocks.air:world.getBlock(x, y, z)==Blocks.air))){
writer.beginObject().setIndent("");
writer.name("block").value("hbm:" + ((dir == ForgeDirection.EAST || dir == ForgeDirection.WEST) ? world.getBlock(z, y, x).getUnlocalizedName():world.getBlock(x, y, z).getUnlocalizedName()));
writer.name("x").value(x - anchorX);
writer.name("y").value(y - anchorY);
writer.name("z").value((dir == ForgeDirection.EAST || dir == ForgeDirection.WEST)?anchorZ - z : z - anchorZ);
writer.name("metas").beginArray();
writer.value(((dir == ForgeDirection.EAST || dir == ForgeDirection.WEST) ? world.getBlockMetadata(z, y, x):world.getBlockMetadata(x, y, z)));
writer.endArray();
writer.endObject().setIndent(" ");
}
}
}
}
writer.endArray();
writer.endObject();
writer.close();
}catch(IOException e) {
e.printStackTrace();
}
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ){
Block b = world.getBlock(x, y, z);
if(b == ModBlocks.cm_anchor) {
this.setAnchor(stack, x, y, z);
return true;
}
if(this.getAnchor(stack) == null) {
return false;
}
if(!stack.stackTagCompound.hasKey("x1")) {
stack.stackTagCompound.setInteger("x1", x);
stack.stackTagCompound.setInteger("y1", y);
stack.stackTagCompound.setInteger("z1", z);
}
else if(!stack.stackTagCompound.hasKey("x2")){
stack.stackTagCompound.setInteger("x2", x);
stack.stackTagCompound.setInteger("y2", y);
stack.stackTagCompound.setInteger("z2", z);
}
else{
writeToFile(file,stack,world);
stack.stackTagCompound.removeTag("x1");
stack.stackTagCompound.removeTag("y1");
stack.stackTagCompound.removeTag("z1");
stack.stackTagCompound.removeTag("x2");
stack.stackTagCompound.removeTag("y2");
stack.stackTagCompound.removeTag("z2");
}
return true;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
super.addInformation(stack, player, list, ext);
list.add(EnumChatFormatting.YELLOW + "Click Custom Machine Structure Positioning Anchor to");
list.add(EnumChatFormatting.YELLOW + "Confirm the location of the custom machine core block.");
list.add(EnumChatFormatting.YELLOW + "Output all blocks between Position1 and Position2 with");
list.add(EnumChatFormatting.YELLOW + "metadata to \"CMstructureOutput.txt\" in hbmConfig.");
}
@Override
public void printHook(RenderGameOverlayEvent.Pre event, World world, int x, int y, int z) {
ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItem();
List<String> text = new ArrayList();
BlockPos anchor = getAnchor(stack);
if(anchor == null) {
text.add(EnumChatFormatting.RED + "No Anchor");
} else {
int anchorX = stack.stackTagCompound.getInteger("anchorX");
int anchorY = stack.stackTagCompound.getInteger("anchorY");
int anchorZ = stack.stackTagCompound.getInteger("anchorZ");
text.add(EnumChatFormatting.GOLD + "Anchor: " + anchorX + " / " + anchorY + " / " + anchorZ);
if(stack.stackTagCompound.hasKey("x1")){
int x1=stack.stackTagCompound.getInteger("x1");
int y1=stack.stackTagCompound.getInteger("y1");
int z1=stack.stackTagCompound.getInteger("z1");
text.add(EnumChatFormatting.YELLOW + "Position1: " + x1 + " / " + y1 + " / " + z1);
}
if(stack.stackTagCompound.hasKey("x2")) {
int x2=stack.stackTagCompound.getInteger("x2");
int y2=stack.stackTagCompound.getInteger("y2");
int z2=stack.stackTagCompound.getInteger("z2");
text.add(EnumChatFormatting.YELLOW + "Position2: " + x2 + " / " + y2 + " / " + z2);
}
}
ILookOverlay.printGeneric(event, this.getItemStackDisplayName(stack), 0xffff00, 0x404000, text);
}
}

View File

@ -4240,6 +4240,7 @@ item.volcanic_pickaxe.name=Molten Pickaxe
item.wand_d.name=Debug Wand
item.wand_k.name=Construction Wand
item.wand_s.name=Structure Wand
item.structure_custommachine.name=Custom Machine Structure Output Wand
item.warhead_buster_large.name=Large Bunker Buster Warhead
item.warhead_buster_medium.name=Medium Bunker Buster Warhead
item.warhead_buster_small.name=Small Bunker Buster Warhead
@ -4642,6 +4643,7 @@ tile.cluster_depth_titanium.name=Depth Titanium Ore Cluster
tile.cluster_depth_tungsten.name=Depth Tungsten Ore Cluster
tile.cluster_iron.name=Iron Ore Cluster
tile.cluster_titanium.name=Titanium Ore Cluster
tile.custom_machine_anchor.name=Custom Machine Structure Positioning Anchor
tile.cm_block.alloy.name=Advanced Alloy Machine Casing
tile.cm_block.desh.name=Desh Machine Casing
tile.cm_block.steel.name=Steel Machine Casing

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B