bring NBTStructures to NTMain!

This commit is contained in:
George Paton 2025-02-09 18:39:15 +11:00
parent c49161ab39
commit 3dbe648ebe
80 changed files with 3189 additions and 468 deletions

View File

@ -5,12 +5,15 @@ import com.hbm.handler.ThreeInts;
import com.hbm.interfaces.ICopiable; import com.hbm.interfaces.ICopiable;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IPersistentNBT; import com.hbm.tileentity.IPersistentNBT;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -32,7 +35,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public abstract class BlockDummyable extends BlockContainer implements ICustomBlockHighlight, ICopiable { public abstract class BlockDummyable extends BlockContainer implements ICustomBlockHighlight, ICopiable, INBTTransformable {
public BlockDummyable(Material mat) { public BlockDummyable(Material mat) {
super(mat); super(mat);
@ -116,7 +119,7 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
return findCoreRec(world, x, y, z); return findCoreRec(world, x, y, z);
} }
List<ThreeInts> positions = new ArrayList(); List<ThreeInts> positions = new ArrayList<>();
public int[] findCoreRec(World world, int x, int y, int z) { public int[] findCoreRec(World world, int x, int y, int z) {
@ -216,11 +219,6 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
super.onBlockPlacedBy(world, x, y, z, player, itemStack); super.onBlockPlacedBy(world, x, y, z, player, itemStack);
} }
/*@Override
public void onBlockAdded(World world, int x, int y, int z) {
lastBlockSet = new BlockPos(x, y, z);
}*/
/** /**
* A bit more advanced than the dir modifier, but it is important that the resulting direction meta is in the core range. * A bit more advanced than the dir modifier, but it is important that the resulting direction meta is in the core range.
* Using the "extra" metas is technically possible but requires a bit of tinkering, e.g. preventing a recursive loop * Using the "extra" metas is technically possible but requires a bit of tinkering, e.g. preventing a recursive loop
@ -267,9 +265,9 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
return; return;
// world.setBlockMetadataWithNotify(x, y, z, meta + extra, 3); // world.setBlockMetadataWithNotify(x, y, z, meta + extra, 3);
this.safeRem = true; safeRem = true;
world.setBlock(x, y, z, this, meta + extra, 3); world.setBlock(x, y, z, this, meta + extra, 3);
this.safeRem = false; safeRem = false;
} }
public void removeExtra(World world, int x, int y, int z) { public void removeExtra(World world, int x, int y, int z) {
@ -283,9 +281,9 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
return; return;
// world.setBlockMetadataWithNotify(x, y, z, meta + extra, 3); // world.setBlockMetadataWithNotify(x, y, z, meta + extra, 3);
this.safeRem = true; safeRem = true;
world.setBlock(x, y, z, this, meta - extra, 3); world.setBlock(x, y, z, this, meta - extra, 3);
this.safeRem = false; safeRem = false;
} }
// checks if the dummy metadata is within the extra range // checks if the dummy metadata is within the extra range
@ -423,8 +421,9 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
return !bounding.isEmpty(); return !bounding.isEmpty();
} }
public List<AxisAlignedBB> bounding = new ArrayList(); public List<AxisAlignedBB> bounding = new ArrayList<>();
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) { public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) {
@ -443,7 +442,7 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
z = pos[2]; z = pos[2];
for(AxisAlignedBB aabb :this.bounding) { for(AxisAlignedBB aabb :this.bounding) {
AxisAlignedBB boxlet = getAABBRotationOffset(aabb, x + 0.5, y, z + 0.5, ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z) - this.offset).getRotation(ForgeDirection.UP)); AxisAlignedBB boxlet = getAABBRotationOffset(aabb, x + 0.5, y, z + 0.5, ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z) - offset).getRotation(ForgeDirection.UP));
if(entityBounding.intersectsWith(boxlet)) { if(entityBounding.intersectsWith(boxlet)) {
list.add(boxlet); list.add(boxlet);
@ -504,7 +503,7 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
int meta = world.getBlockMetadata(x, y, z); int meta = world.getBlockMetadata(x, y, z);
ICustomBlockHighlight.setup(); ICustomBlockHighlight.setup();
for(AxisAlignedBB aabb : this.bounding) event.context.drawOutlinedBoundingBox(getAABBRotationOffset(aabb.expand(exp, exp, exp), 0, 0, 0, ForgeDirection.getOrientation(meta - offset).getRotation(ForgeDirection.UP)).getOffsetBoundingBox(x - dX + 0.5, y - dY, z - dZ + 0.5), -1); for(AxisAlignedBB aabb : this.bounding) RenderGlobal.drawOutlinedBoundingBox(getAABBRotationOffset(aabb.expand(exp, exp, exp), 0, 0, 0, ForgeDirection.getOrientation(meta - offset).getRotation(ForgeDirection.UP)).getOffsetBoundingBox(x - dX + 0.5, y - dY, z - dZ + 0.5), -1);
ICustomBlockHighlight.cleanup(); ICustomBlockHighlight.cleanup();
} }
@ -534,4 +533,27 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
return ((ICopiable) tile).infoForDisplay(world, x, y, z); return ((ICopiable) tile).infoForDisplay(world, x, y, z);
return null; return null;
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
boolean isOffset = meta >= 12; // squishing causes issues
boolean isExtra = !isOffset && meta >= extra;
if(isOffset) {
meta -= offset;
} else if(isExtra) {
meta -= extra;
}
meta = INBTTransformable.transformMetaDeco(meta, coordBaseMode);
if(isOffset) {
meta += offset;
} else if(isExtra) {
meta += extra;
}
return meta;
}
} }

View File

@ -11,4 +11,27 @@ public interface IBlockSideRotation {
public static int getRenderType() { public static int getRenderType() {
return renderID; return renderID;
} }
// 0 1 3 2 becomes 0 2 3 1
// I want to smoke that swedish kush because it clearly makes you fucking stupid
public static int topToBottom(int topRotation) {
switch(topRotation) {
case 1: return 2;
case 2: return 1;
default: return topRotation;
}
}
public static boolean isOpposite(int from, int to) {
switch(from) {
case 0: return to == 1;
case 1: return to == 0;
case 2: return to == 3;
case 3: return to == 2;
case 4: return to == 5;
case 5: return to == 4;
default: return false;
}
}
} }

View File

@ -35,6 +35,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
import net.minecraft.block.material.*; import net.minecraft.block.material.*;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -1228,6 +1229,11 @@ public class ModBlocks {
public static Block pink_double_slab; public static Block pink_double_slab;
public static Block pink_stairs; public static Block pink_stairs;
// NBT Structure wand blocks
public static Block wand_air;
public static Block wand_loot;
public static Block wand_jigsaw;
public static Material materialGas = new MaterialGas(); public static Material materialGas = new MaterialGas();
private static void initializeBlock() { private static void initializeBlock() {
@ -2354,6 +2360,10 @@ public class ModBlocks {
pink_slab = new BlockPinkSlab(false, Material.wood).setBlockName("pink_slab").setStepSound(Block.soundTypeWood).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pink_planks"); pink_slab = new BlockPinkSlab(false, Material.wood).setBlockName("pink_slab").setStepSound(Block.soundTypeWood).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pink_planks");
pink_double_slab = new BlockPinkSlab(true, Material.wood).setBlockName("pink_double_slab").setStepSound(Block.soundTypeWood).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pink_planks"); pink_double_slab = new BlockPinkSlab(true, Material.wood).setBlockName("pink_double_slab").setStepSound(Block.soundTypeWood).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pink_planks");
pink_stairs = new BlockGenericStairs(pink_planks, 0).setBlockName("pink_stairs").setStepSound(Block.soundTypeWood).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pink_planks"); pink_stairs = new BlockGenericStairs(pink_planks, 0).setBlockName("pink_stairs").setStepSound(Block.soundTypeWood).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":pink_planks");
wand_air = new BlockWand(Blocks.air).setBlockName("wand_air").setBlockTextureName(RefStrings.MODID + ":wand_air");
wand_loot = new BlockWandLoot().setBlockName("wand_loot").setBlockTextureName(RefStrings.MODID + ":wand_loot");
wand_jigsaw = new BlockWandJigsaw().setBlockName("wand_jigsaw").setBlockTextureName(RefStrings.MODID + ":wand_jigsaw");
} }
private static void registerBlock() { private static void registerBlock() {
@ -3475,6 +3485,10 @@ public class ModBlocks {
GameRegistry.registerBlock(pink_slab, pink_slab.getUnlocalizedName()); GameRegistry.registerBlock(pink_slab, pink_slab.getUnlocalizedName());
GameRegistry.registerBlock(pink_double_slab, pink_double_slab.getUnlocalizedName()); GameRegistry.registerBlock(pink_double_slab, pink_double_slab.getUnlocalizedName());
GameRegistry.registerBlock(pink_stairs, pink_stairs.getUnlocalizedName()); GameRegistry.registerBlock(pink_stairs, pink_stairs.getUnlocalizedName());
register(wand_air);
register(wand_loot);
register(wand_jigsaw);
} }
private static void register(Block b) { private static void register(Block b) {

View File

@ -4,6 +4,9 @@ import com.hbm.inventory.gui.GUIScreenBobble;
import com.hbm.items.special.ItemPlasticScrap.ScrapType; import com.hbm.items.special.ItemPlasticScrap.ScrapType;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.world.gen.INBTTileEntityTransformable;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -31,7 +34,7 @@ import net.minecraft.world.World;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class BlockBobble extends BlockContainer implements IGUIProvider { public class BlockBobble extends BlockContainer implements IGUIProvider, INBTTransformable {
public BlockBobble() { public BlockBobble() {
super(Material.iron); super(Material.iron);
@ -136,12 +139,17 @@ public class BlockBobble extends BlockContainer implements IGUIProvider {
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return (meta + coordBaseMode * 4) % 16;
}
@Override @Override
public TileEntity createNewTileEntity(World world, int meta) { public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityBobble(); return new TileEntityBobble();
} }
public static class TileEntityBobble extends TileEntity { public static class TileEntityBobble extends TileEntity implements INBTTileEntityTransformable {
public BobbleType type = BobbleType.NONE; public BobbleType type = BobbleType.NONE;
@ -173,6 +181,11 @@ public class BlockBobble extends BlockContainer implements IGUIProvider {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setByte("type", (byte) type.ordinal()); nbt.setByte("type", (byte) type.ordinal());
} }
@Override
public void transformTE(World world, int coordBaseMode) {
type = BobbleType.values()[world.rand.nextInt(BobbleType.values().length - 1) + 1];
}
} }
public static enum BobbleType { public static enum BobbleType {

View File

@ -2,6 +2,7 @@ package com.hbm.blocks.generic;
import com.hbm.blocks.BlockMulti; import com.hbm.blocks.BlockMulti;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -14,7 +15,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockDecoCRT extends BlockMulti { public class BlockDecoCRT extends BlockMulti implements INBTTransformable {
protected String[] variants = new String[] {"crt_clean", "crt_broken", "crt_blinking", "crt_bsod"}; protected String[] variants = new String[] {"crt_clean", "crt_broken", "crt_blinking", "crt_bsod"};
@SideOnly(Side.CLIENT) protected IIcon[] icons; @SideOnly(Side.CLIENT) protected IIcon[] icons;
@ -73,4 +74,10 @@ public class BlockDecoCRT extends BlockMulti {
public int getSubCount() { public int getSubCount() {
return 4; return 4;
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDecoModel(meta, coordBaseMode);
}
} }

View File

@ -1,6 +1,7 @@
package com.hbm.blocks.generic; package com.hbm.blocks.generic;
import com.hbm.blocks.BlockEnumMulti; import com.hbm.blocks.BlockEnumMulti;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -11,7 +12,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockDecoModel extends BlockEnumMulti { public class BlockDecoModel extends BlockEnumMulti implements INBTTransformable {
public BlockDecoModel(Material mat, Class<? extends Enum> theEnum, boolean multiName, boolean multiTexture) { public BlockDecoModel(Material mat, Class<? extends Enum> theEnum, boolean multiName, boolean multiTexture) {
super(mat, theEnum, multiName, multiTexture); super(mat, theEnum, multiName, multiTexture);
@ -104,4 +105,33 @@ public class BlockDecoModel extends BlockEnumMulti {
this.setBlockBoundsBasedOnState(world, x, y, z); this.setBlockBoundsBasedOnState(world, x, y, z);
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
//N: 0b00, S: 0b01, W: 0b10, E: 0b11
int rot = meta >> 2;
int type = meta & 3;
switch(coordBaseMode) {
default: //South
break;
case 1: //West
if((rot & 3) < 2) //N & S can just have bits toggled
rot = rot ^ 3;
else //W & E can just have first bit set to 0
rot = rot ^ 2;
break;
case 2: //North
rot = rot ^ 1; //N, W, E & S can just have first bit toggled
break;
case 3: //East
if((rot & 3) < 2)//N & S can just have second bit set to 1
rot = rot ^ 2;
else //W & E can just have bits toggled
rot = rot ^ 3;
break;
}
//genuinely like. why did i do that
return (rot << 2) | type; //To accommodate for BlockDecoModel's shift in the rotation bits; otherwise, simply bit-shift right and or any non-rotation meta after
}
} }

View File

@ -2,6 +2,7 @@ package com.hbm.blocks.generic;
import com.hbm.blocks.BlockMulti; import com.hbm.blocks.BlockMulti;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -16,7 +17,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockDecoToaster extends BlockMulti { public class BlockDecoToaster extends BlockMulti implements INBTTransformable {
protected String[] variants = new String[] {"toaster_iron", "toaster_steel", "toaster_wood"}; protected String[] variants = new String[] {"toaster_iron", "toaster_steel", "toaster_wood"};
@SideOnly(Side.CLIENT) protected IIcon[] icons; @SideOnly(Side.CLIENT) protected IIcon[] icons;
@ -90,4 +91,10 @@ public class BlockDecoToaster extends BlockMulti {
this.setBlockBoundsBasedOnState(world, x, y, z); this.setBlockBoundsBasedOnState(world, x, y, z);
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDecoModel(meta, coordBaseMode);
}
} }

View File

@ -4,6 +4,7 @@ import java.util.List;
import com.hbm.blocks.ITooltipProvider; import com.hbm.blocks.ITooltipProvider;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -16,7 +17,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockPipe extends Block implements ITooltipProvider { public class BlockPipe extends Block implements ITooltipProvider, INBTTransformable {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
private IIcon sideIcon; private IIcon sideIcon;
@ -92,4 +93,10 @@ public class BlockPipe extends Block implements ITooltipProvider {
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
list.add("Purely decorative"); list.add("Purely decorative");
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaPillar(meta, coordBaseMode);
}
} }

View File

@ -0,0 +1,51 @@
package com.hbm.blocks.generic;
import cpw.mods.fml.client.registry.RenderingRegistry;
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.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockWand extends Block {
public final Block exportAs;
public BlockWand(Block exportAs) {
super(Material.glass);
this.exportAs = exportAs;
setBlockBounds(1F/16F, 1F/16F, 1F/16F, 15F/16F, 15F/16F, 15F/16F);
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
return null;
}
public static int renderID = RenderingRegistry.getNextAvailableRenderId();
@Override
public int getRenderType() {
return renderID;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) {
Block block = world.getBlock(x, y, z);
return block != this;
}
}

View File

@ -0,0 +1,387 @@
package com.hbm.blocks.generic;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Keyboard;
import com.hbm.blocks.IBlockSideRotation;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toserver.NBTControlPacket;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityLoadedBase;
import com.hbm.util.BufferUtil;
import com.hbm.util.I18nUtil;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.material.Material;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
public class BlockWandJigsaw extends BlockContainer implements IBlockSideRotation, INBTTransformable, IGUIProvider, ILookOverlay {
private IIcon iconTop;
private IIcon iconSide;
private IIcon iconBack;
public BlockWandJigsaw() {
super(Material.iron);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityWandJigsaw();
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
int l = BlockPistonBase.determineOrientation(world, x, y, z, player);
world.setBlockMetadataWithNotify(x, y, z, l, 2);
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":wand_jigsaw");
this.iconTop = iconRegister.registerIcon(RefStrings.MODID + ":wand_jigsaw_top");
this.iconSide = iconRegister.registerIcon(RefStrings.MODID + ":wand_jigsaw_side");
this.iconBack = iconRegister.registerIcon(RefStrings.MODID + ":wand_jigsaw_back");
}
@Override
public IIcon getIcon(int side, int meta) {
if(side == meta) return blockIcon;
if(IBlockSideRotation.isOpposite(side, meta)) return iconBack;
if(side <= 1) return iconTop;
if(side > 3 && meta <= 1) return iconTop;
return iconSide;
}
@Override
public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) {
if(side == 0) return IBlockSideRotation.topToBottom(getRotationFromSide(world, x, y, z, 1));
int meta = world.getBlockMetadata(x, y, z);
if(side == meta || IBlockSideRotation.isOpposite(side, meta)) return 0;
// downwards facing has no changes, upwards flips anything not handled already
if(meta == 0) return 0;
if(meta == 1) return 3;
// top (and bottom) is rotated fairly normally
if(side == 1) {
switch(meta) {
case 2: return 3;
case 3: return 0;
case 4: return 1;
case 5: return 2;
}
}
// you know what I aint explaining further, it's a fucking mess here
if(meta == 2) return side == 4 ? 2 : 1;
if(meta == 3) return side == 4 ? 1 : 2;
if(meta == 4) return side == 2 ? 1 : 2;
if(meta == 5) return side == 2 ? 2 : 1;
return 0;
}
@Override
public int getRenderType() {
return IBlockSideRotation.getRenderType();
}
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDeco(meta, coordBaseMode);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileEntityWandJigsaw)) return false;
TileEntityWandJigsaw jigsaw = (TileEntityWandJigsaw) te;
if(!player.isSneaking()) {
Block block = getBlock(world, player.getHeldItem());
if(block == ModBlocks.wand_air) block = Blocks.air;
if(block != null && block != ModBlocks.wand_jigsaw && block != ModBlocks.wand_loot) {
jigsaw.replaceBlock = block;
jigsaw.replaceMeta = player.getHeldItem().getItemDamage();
return true;
}
if(world.isRemote) FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);
return true;
}
return false;
}
private Block getBlock(World world, ItemStack stack) {
if(stack == null) return null;
if(!(stack.getItem() instanceof ItemBlock)) return null;
return ((ItemBlock) stack.getItem()).field_150939_a;
}
@Override
@SideOnly(Side.CLIENT)
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GuiWandJigsaw((TileEntityWandJigsaw) world.getTileEntity(x, y, z));
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
public void printHook(Pre event, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileEntityWandJigsaw)) return;
TileEntityWandJigsaw jigsaw = (TileEntityWandJigsaw) te;
List<String> text = new ArrayList<String>();
text.add(EnumChatFormatting.GRAY + "Target pool: " + EnumChatFormatting.RESET + jigsaw.pool);
text.add(EnumChatFormatting.GRAY + "Name: " + EnumChatFormatting.RESET + jigsaw.name);
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);
text.add(EnumChatFormatting.GRAY + "Selection/Placement priority: " + EnumChatFormatting.RESET + jigsaw.selectionPriority + "/" + jigsaw.placementPriority);
text.add(EnumChatFormatting.GRAY + "Joint type: " + EnumChatFormatting.RESET + (jigsaw.isRollable ? "Rollable" : "Aligned"));
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
}
public static class TileEntityWandJigsaw extends TileEntityLoadedBase implements IControlReceiver {
private int selectionPriority = 0; // higher priority = this jigsaw block is selected first for generation
private int placementPriority = 0; // higher priority = children of this jigsaw block are checked for jigsaw blocks of their own and selected first
private String pool = "default";
private String name = "default";
private String target = "default";
private Block replaceBlock = Blocks.air;
private int replaceMeta = 0;
private boolean isRollable = true; // sets joint type, rollable joints can be placed in any orientation for vertical jigsaw connections
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
networkPackNT(15);
}
}
@Override
public void serialize(ByteBuf buf) {
buf.writeInt(selectionPriority);
buf.writeInt(placementPriority);
BufferUtil.writeString(buf, pool);
BufferUtil.writeString(buf, name);
BufferUtil.writeString(buf, target);
buf.writeInt(Block.getIdFromBlock(replaceBlock));
buf.writeInt(replaceMeta);
buf.writeBoolean(isRollable);
}
@Override
public void deserialize(ByteBuf buf) {
selectionPriority = buf.readInt();
placementPriority = buf.readInt();
pool = BufferUtil.readString(buf);
name = BufferUtil.readString(buf);
target = BufferUtil.readString(buf);
replaceBlock = Block.getBlockById(buf.readInt());
replaceMeta = buf.readInt();
isRollable = buf.readBoolean();
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setInteger("direction", this.getBlockMetadata());
nbt.setInteger("selection", selectionPriority);
nbt.setInteger("placement", placementPriority);
nbt.setString("pool", pool);
nbt.setString("name", name);
nbt.setString("target", target);
nbt.setString("block", GameRegistry.findUniqueIdentifierFor(replaceBlock).toString());
nbt.setInteger("meta", replaceMeta);
nbt.setBoolean("roll", isRollable);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
selectionPriority = nbt.getInteger("selection");
placementPriority = nbt.getInteger("placement");
pool = nbt.getString("pool");
name = nbt.getString("name");
target = nbt.getString("target");
replaceBlock = Block.getBlockFromName(nbt.getString("block"));
replaceMeta = nbt.getInteger("meta");
isRollable = nbt.getBoolean("roll");
}
@Override
public boolean hasPermission(EntityPlayer player) {
return true;
}
@Override
public void receiveControl(NBTTagCompound nbt) {
readFromNBT(nbt);
markDirty();
}
}
public static class GuiWandJigsaw extends GuiScreen {
private final TileEntityWandJigsaw jigsaw;
private GuiTextField textPool;
private GuiTextField textName;
private GuiTextField textTarget;
private GuiTextField textSelectionPriority;
private GuiTextField textPlacementPriority;
private GuiButton jointToggle;
public GuiWandJigsaw(TileEntityWandJigsaw jigsaw) {
this.jigsaw = jigsaw;
}
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
textPool = new GuiTextField(fontRendererObj, this.width / 2 - 150, 50, 300, 20);
textPool.setText(jigsaw.pool);
textName = new GuiTextField(fontRendererObj, this.width / 2 - 150, 100, 140, 20);
textName.setText(jigsaw.name);
textTarget = new GuiTextField(fontRendererObj, this.width / 2 + 10, 100, 140, 20);
textTarget.setText(jigsaw.target);
textSelectionPriority = new GuiTextField(fontRendererObj, this.width / 2 - 150, 150, 90, 20);
textSelectionPriority.setText("" + jigsaw.selectionPriority);
textPlacementPriority = new GuiTextField(fontRendererObj, this.width / 2 - 40, 150, 90, 20);
textPlacementPriority.setText("" + jigsaw.placementPriority);
jointToggle = new GuiButton(0, this.width / 2 + 60, 150, 90, 20, jigsaw.isRollable ? "Rollable" : "Aligned");
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
drawString(fontRendererObj, "Target pool:", this.width / 2 - 150, 37, 0xA0A0A0);
textPool.drawTextBox();
drawString(fontRendererObj, "Name:", this.width / 2 - 150, 87, 0xA0A0A0);
textName.drawTextBox();
drawString(fontRendererObj, "Target name:", this.width / 2 + 10, 87, 0xA0A0A0);
textTarget.drawTextBox();
drawString(fontRendererObj, "Selection priority:", this.width / 2 - 150, 137, 0xA0A0A0);
textSelectionPriority.drawTextBox();
drawString(fontRendererObj, "Placement priority:", this.width / 2 - 40, 137, 0xA0A0A0);
textPlacementPriority.drawTextBox();
drawString(fontRendererObj, "Joint type:", this.width / 2 + 60, 137, 0xA0A0A0);
jointToggle.drawButton(mc, mouseX, mouseY);
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
NBTTagCompound data = new NBTTagCompound();
jigsaw.writeToNBT(data);
data.setString("pool", textPool.getText());
data.setString("name", textName.getText());
data.setString("target", textTarget.getText());
try { data.setInteger("selection", Integer.parseInt(textSelectionPriority.getText())); } catch(Exception ex) {}
try { data.setInteger("placement", Integer.parseInt(textPlacementPriority.getText())); } catch(Exception ex) {}
data.setBoolean("roll", jointToggle.displayString == "Rollable");
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, jigsaw.xCoord, jigsaw.yCoord, jigsaw.zCoord));
}
@Override
protected void keyTyped(char typedChar, int keyCode) {
super.keyTyped(typedChar, keyCode);
textPool.textboxKeyTyped(typedChar, keyCode);
textName.textboxKeyTyped(typedChar, keyCode);
textTarget.textboxKeyTyped(typedChar, keyCode);
textSelectionPriority.textboxKeyTyped(typedChar, keyCode);
textPlacementPriority.textboxKeyTyped(typedChar, keyCode);
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
textPool.mouseClicked(mouseX, mouseY, mouseButton);
textName.mouseClicked(mouseX, mouseY, mouseButton);
textTarget.mouseClicked(mouseX, mouseY, mouseButton);
textSelectionPriority.mouseClicked(mouseX, mouseY, mouseButton);
textPlacementPriority.mouseClicked(mouseX, mouseY, mouseButton);
if(jointToggle.mousePressed(mc, mouseX, mouseY)) {
System.out.println("displayString: " + jointToggle.displayString);
jointToggle.displayString = jointToggle.displayString == "Rollable" ? "Aligned" : "Rollable";
}
}
}
}

View File

@ -0,0 +1,338 @@
package com.hbm.blocks.generic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import com.hbm.blocks.IBlockSideRotation;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ITooltipProvider;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.StructureConfig;
import com.hbm.itempool.ItemPool;
import com.hbm.lib.RefStrings;
import com.hbm.tileentity.TileEntityLoadedBase;
import com.hbm.util.BufferUtil;
import com.hbm.util.I18nUtil;
import com.hbm.util.LootGenerator;
import com.hbm.world.gen.INBTTileEntityTransformable;
import com.mojang.authlib.GameProfile;
import api.hbm.block.IToolable;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
public class BlockWandLoot extends BlockContainer implements ILookOverlay, IToolable, ITooltipProvider, IBlockSideRotation {
@SideOnly(Side.CLIENT) protected IIcon iconTop;
public BlockWandLoot() {
super(Material.iron);
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":wand_loot");
this.iconTop = iconRegister.registerIcon(RefStrings.MODID + ":wand_loot_top");
}
@Override
public IIcon getIcon(int side, int meta) {
return (side <= 1) ? iconTop : blockIcon;
}
@Override
public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) {
if(side == 0) return IBlockSideRotation.topToBottom(world.getBlockMetadata(x, y, z));
if(side == 1) return world.getBlockMetadata(x, y, z);
return 0;
}
@Override
public int getRenderType() {
return IBlockSideRotation.getRenderType();
}
@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, 3, 2);
if(i == 1) world.setBlockMetadataWithNotify(x, y, z, 2, 2);
if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 0, 2);
if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 1, 2);
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileEntityWandLoot)) return;
((TileEntityWandLoot) te).placedRotation = player.rotationYaw;
}
@Override
public void printHook(Pre event, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileEntityWandLoot)) return;
TileEntityWandLoot loot = (TileEntityWandLoot) te;
List<String> text = new ArrayList<String>();
text.add("Will replace with: " + loot.replaceBlock.getUnlocalizedName());
text.add(" meta: " + loot.replaceMeta);
text.add("Loot pool: " + loot.poolName);
if(loot.replaceBlock != ModBlocks.deco_loot) {
text.add("Minimum items: " + loot.minItems);
text.add("Maximum items: " + loot.maxItems);
}
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
list.add("Define loot crates/piles in .nbt structures");
list.add(EnumChatFormatting.GOLD + "Use screwdriver to increase/decrease minimum loot");
list.add(EnumChatFormatting.GOLD + "Use hand drill to increase/decrease maximum loot");
list.add(EnumChatFormatting.GOLD + "Use defuser to cycle loot types");
list.add(EnumChatFormatting.GOLD + "Use container block to set the block that spawns with loot inside");
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileEntityWandLoot)) return false;
TileEntityWandLoot loot = (TileEntityWandLoot) te;
if(!player.isSneaking()) {
Block block = getLootableBlock(world, player.getHeldItem());
if(block != null) {
loot.replaceBlock = block;
loot.replaceMeta = player.getHeldItem().getItemDamage();
List<String> poolNames = loot.getPoolNames(block == ModBlocks.deco_loot);
if(!poolNames.contains(loot.poolName)) {
loot.poolName = poolNames.get(0);
}
return true;
}
}
return false;
}
private Block getLootableBlock(World world, ItemStack stack) {
if(stack == null) return null;
if(stack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) stack.getItem()).field_150939_a;
if(block == ModBlocks.deco_loot) return block;
if(block instanceof ITileEntityProvider) {
TileEntity te = ((ITileEntityProvider) block).createNewTileEntity(world, 12);
if(te instanceof IInventory) return block;
}
}
return null;
}
@Override
public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileEntityWandLoot)) return false;
TileEntityWandLoot loot = (TileEntityWandLoot) te;
switch(tool) {
case SCREWDRIVER:
if(player.isSneaking()) {
loot.minItems--;
if(loot.minItems < 0) loot.minItems = 0;
} else {
loot.minItems++;
loot.maxItems = Math.max(loot.minItems, loot.maxItems);
}
return true;
case HAND_DRILL:
if(player.isSneaking()) {
loot.maxItems--;
if(loot.maxItems < 0) loot.maxItems = 0;
loot.minItems = Math.min(loot.minItems, loot.maxItems);
} else {
loot.maxItems++;
}
return true;
case DEFUSER:
List<String> poolNames = loot.getPoolNames(loot.replaceBlock == ModBlocks.deco_loot);
int index = poolNames.indexOf(loot.poolName);
index += player.isSneaking() ? -1 : 1;
index = MathHelper.clamp_int(index, 0, poolNames.size() - 1);
loot.poolName = poolNames.get(index);
return true;
default: return false;
}
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityWandLoot();
}
public static class TileEntityWandLoot extends TileEntityLoadedBase implements INBTTileEntityTransformable {
private boolean triggerReplace;
private Block replaceBlock = ModBlocks.deco_loot;
private int replaceMeta;
private String poolName = LootGenerator.LOOT_BOOKLET;
private int minItems;
private int maxItems = 1;
private float placedRotation;
private static final GameProfile FAKE_PROFILE = new GameProfile(UUID.fromString("839eb18c-50bc-400c-8291-9383f09763e7"), "[NTM]");
private static FakePlayer fakePlayer;
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
if(triggerReplace) {
// On the first tick of this TE, replace with intended block and fill with loot
replace();
} else {
networkPackNT(15);
}
}
}
private void replace() {
WeightedRandomChestContent[] pool = ItemPool.getPool(poolName);
worldObj.setBlock(xCoord, yCoord, zCoord, replaceBlock, replaceMeta, 2);
TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord);
if(te instanceof IInventory) {
int count = minItems;
if(maxItems - minItems > 0) count += worldObj.rand.nextInt(maxItems - minItems);
WeightedRandomChestContent.generateChestContents(worldObj.rand, pool, (IInventory) te, count);
} else if(te instanceof BlockLoot.TileEntityLoot) {
LootGenerator.applyLoot(worldObj, xCoord, yCoord, zCoord, poolName);
}
// Shouldn't happen but let's guard anyway, if it fails we just don't rotate the chest block correctly
if(!(worldObj instanceof WorldServer)) return;
if(fakePlayer == null || fakePlayer.worldObj != worldObj) {
fakePlayer = FakePlayerFactory.get((WorldServer)worldObj, FAKE_PROFILE);
}
fakePlayer.rotationYaw = fakePlayer.rotationYawHead = placedRotation;
ItemStack fakeStack = new ItemStack(replaceBlock, 1, replaceMeta);
replaceBlock.onBlockPlacedBy(worldObj, xCoord, yCoord, zCoord, fakePlayer, fakeStack);
}
private List<String> getPoolNames(boolean loot) {
if(loot) return Arrays.asList(LootGenerator.getLootNames());
List<String> names = new ArrayList<>();
names.addAll(ItemPool.pools.keySet());
return names;
}
@Override
public void transformTE(World world, int coordBaseMode) {
triggerReplace = !StructureConfig.debugStructures;
placedRotation = MathHelper.wrapAngleTo180_float(placedRotation + coordBaseMode * 90);
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
Block writeBlock = replaceBlock == null ? ModBlocks.deco_loot : replaceBlock;
nbt.setString("block", GameRegistry.findUniqueIdentifierFor(writeBlock).toString());
nbt.setInteger("meta", replaceMeta);
nbt.setInteger("min", minItems);
nbt.setInteger("max", maxItems);
nbt.setString("pool", poolName);
nbt.setFloat("rot", placedRotation);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
replaceBlock = Block.getBlockFromName(nbt.getString("block"));
replaceMeta = nbt.getInteger("meta");
minItems = nbt.getInteger("min");
maxItems = nbt.getInteger("max");
poolName = nbt.getString("pool");
placedRotation = nbt.getFloat("rot");
if(replaceBlock == null) replaceBlock = ModBlocks.deco_loot;
}
@Override
public void serialize(ByteBuf buf) {
buf.writeInt(Block.getIdFromBlock(replaceBlock));
buf.writeInt(replaceMeta);
buf.writeInt(minItems);
buf.writeInt(maxItems);
BufferUtil.writeString(buf, poolName);
}
@Override
public void deserialize(ByteBuf buf) {
replaceBlock = Block.getBlockById(buf.readInt());
replaceMeta = buf.readInt();
minItems = buf.readInt();
maxItems = buf.readInt();
poolName = BufferUtil.readString(buf);
}
}
}

View File

@ -6,6 +6,7 @@ import java.util.Random;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.tileentity.deco.TileEntityDecoBlock; import com.hbm.tileentity.deco.TileEntityDecoBlock;
import com.hbm.world.gen.INBTTransformable;
import api.hbm.block.IToolable; import api.hbm.block.IToolable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
@ -24,7 +25,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
public class DecoBlock extends BlockContainer implements IToolable { public class DecoBlock extends BlockContainer implements IToolable, INBTTransformable {
Random rand = new Random(); Random rand = new Random();
@ -181,4 +182,9 @@ public class DecoBlock extends BlockContainer implements IToolable {
super.addCollisionBoxesToList(world, x, y, z, aabb, list, collider); super.addCollisionBoxesToList(world, x, y, z, aabb, list, collider);
} }
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDeco(meta, coordBaseMode);
}
} }

View File

@ -1,6 +1,7 @@
package com.hbm.blocks.generic; package com.hbm.blocks.generic;
import com.hbm.tileentity.deco.TileEntityDecoPoleSatelliteReceiver; import com.hbm.tileentity.deco.TileEntityDecoPoleSatelliteReceiver;
import com.hbm.world.gen.INBTTransformable;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -10,7 +11,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
public class DecoPoleSatelliteReceiver extends BlockContainer { public class DecoPoleSatelliteReceiver extends BlockContainer implements INBTTransformable {
public DecoPoleSatelliteReceiver(Material p_i45386_1_) { public DecoPoleSatelliteReceiver(Material p_i45386_1_) {
super(p_i45386_1_); super(p_i45386_1_);
@ -58,4 +59,9 @@ public class DecoPoleSatelliteReceiver extends BlockContainer {
} }
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDeco(meta, coordBaseMode);
}
} }

View File

@ -1,5 +1,7 @@
package com.hbm.blocks.generic; package com.hbm.blocks.generic;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -9,7 +11,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
public class DecoTapeRecorder extends BlockContainer { public class DecoTapeRecorder extends BlockContainer implements INBTTransformable {
public DecoTapeRecorder(Material p_i45386_1_) { public DecoTapeRecorder(Material p_i45386_1_) {
super(p_i45386_1_); super(p_i45386_1_);
@ -59,4 +61,9 @@ public class DecoTapeRecorder extends BlockContainer {
} }
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDeco(meta, coordBaseMode);
}
} }

View File

@ -7,6 +7,7 @@ import java.util.Random;
import com.hbm.blocks.BlockEnums.LightType; import com.hbm.blocks.BlockEnums.LightType;
import com.hbm.blocks.ISpotlight; import com.hbm.blocks.ISpotlight;
import com.hbm.main.ResourceManager; import com.hbm.main.ResourceManager;
import com.hbm.world.gen.INBTTransformable;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -14,6 +15,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab; import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
@ -22,7 +24,7 @@ import net.minecraft.world.World;
import net.minecraftforge.client.model.obj.WavefrontObject; import net.minecraftforge.client.model.obj.WavefrontObject;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class Spotlight extends Block implements ISpotlight { public class Spotlight extends Block implements ISpotlight, INBTTransformable {
// I'd be extending the ReinforcedLamp class if it wasn't for the inverted behaviour of these specific lights // I'd be extending the ReinforcedLamp class if it wasn't for the inverted behaviour of these specific lights
// I want these blocks to be eminently useful, so removing the need for redstone by default is desired, // I want these blocks to be eminently useful, so removing the need for redstone by default is desired,
@ -123,6 +125,8 @@ public class Spotlight extends Block implements ISpotlight {
} }
private boolean updatePower(World world, int x, int y, int z) { private boolean updatePower(World world, int x, int y, int z) {
if(isBroken(world.getBlockMetadata(x, y, z))) return false;
boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z); boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z);
if(isOn && isPowered) { if(isOn && isPowered) {
world.scheduleBlockUpdate(x, y, z, this, 4); world.scheduleBlockUpdate(x, y, z, this, 4);
@ -159,6 +163,7 @@ public class Spotlight extends Block implements ISpotlight {
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) { public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
if(world.isRemote) return; if(world.isRemote) return;
if(neighborBlock instanceof SpotlightBeam) return; if(neighborBlock instanceof SpotlightBeam) return;
if(neighborBlock == Blocks.air) return;
ForgeDirection dir = getDirection(world, x, y, z); ForgeDirection dir = getDirection(world, x, y, z);
@ -215,6 +220,10 @@ public class Spotlight extends Block implements ISpotlight {
return ForgeDirection.getOrientation(metadata >> 1); return ForgeDirection.getOrientation(metadata >> 1);
} }
public boolean isBroken(int metadata) {
return (metadata & 1) == 1;
}
@Override @Override
public Item getItemDropped(int i, Random r, int j) { public Item getItemDropped(int i, Random r, int j) {
return Item.getItemFromBlock(getOn()); return Item.getItemFromBlock(getOn());
@ -313,4 +322,19 @@ public class Spotlight extends Block implements ISpotlight {
public int getBeamLength() { public int getBeamLength() {
return this.beamLength; return this.beamLength;
} }
@Override
public int transformMeta(int meta, int coordBaseMode) {
// +1 to set as broken, won't turn on until broken and replaced
return (INBTTransformable.transformMetaDeco(meta >> 1, coordBaseMode) << 1) + 1;
}
@Override
public Block transformBlock(Block block) {
if(block == ModBlocks.spotlight_incandescent) return ModBlocks.spotlight_incandescent_off;
if(block == ModBlocks.spotlight_fluoro) return ModBlocks.spotlight_fluoro_off;
if(block == ModBlocks.spotlight_halogen) return ModBlocks.spotlight_halogen_off;
return block;
}
} }

View File

@ -15,6 +15,8 @@ public class StructureConfig {
public static double lootAmountFactor = 1D; public static double lootAmountFactor = 1D;
public static boolean debugStructures = false;
public static void loadFromConfig(Configuration config) { public static void loadFromConfig(Configuration config) {
final String CATEGORY_STRUCTURES = CommonConfig.CATEGORY_STRUCTURES; final String CATEGORY_STRUCTURES = CommonConfig.CATEGORY_STRUCTURES;
@ -28,6 +30,8 @@ public class StructureConfig {
lootAmountFactor = CommonConfig.createConfigDouble(config, CATEGORY_STRUCTURES, "5.03_lootAmountFactor", "General factor for loot spawns. Applies to spawned IInventories, not loot blocks.", 1D); lootAmountFactor = CommonConfig.createConfigDouble(config, CATEGORY_STRUCTURES, "5.03_lootAmountFactor", "General factor for loot spawns. Applies to spawned IInventories, not loot blocks.", 1D);
debugStructures = CommonConfig.createConfigBool(config, CATEGORY_STRUCTURES, "5.04_debugStructures", "If enabled, special structure blocks like jigsaw blocks will not be transformed after generating", false);
structureMinChunks = CommonConfig.setDef(structureMinChunks, 8); structureMinChunks = CommonConfig.setDef(structureMinChunks, 8);
structureMaxChunks = CommonConfig.setDef(structureMaxChunks, 24); structureMaxChunks = CommonConfig.setDef(structureMaxChunks, 24);

View File

@ -6,8 +6,10 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.items.special.ItemBookLore;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -67,6 +69,48 @@ public class MKUCraftingHandler implements IRecipe {
MKURecipe = list.toArray(new ItemStack[9]); MKURecipe = list.toArray(new ItemStack[9]);
} }
public static Item getMKUItem(World world) {
switch(world.rand.nextInt(6)) {
case 0: return ModItems.powder_iodine;
case 1: return ModItems.powder_fire;
case 2: return ModItems.dust;
case 3: return ModItems.ingot_mercury;
case 4: return ModItems.morning_glory;
case 5: return ModItems.syringe_metal_empty;
default: return ModItems.flame_pony;
}
}
public static ItemStack generateBook(World world, Item mkuItem) {
MKUCraftingHandler.generateRecipe(world);
ItemStack[] recipe = MKUCraftingHandler.MKURecipe;
if(recipe == null) return new ItemStack(ModItems.flame_pony);
String key = null;
int pages = 1;
if(mkuItem == ModItems.powder_iodine) { key = "book_iodine"; pages = 3; }
if(mkuItem == ModItems.powder_fire) { key = "book_phosphorous"; pages = 2; }
if(mkuItem == ModItems.dust) { key = "book_dust"; pages = 3; }
if(mkuItem == ModItems.ingot_mercury) { key = "book_mercury"; pages = 2; }
if(mkuItem == ModItems.morning_glory) { key = "book_flower"; pages = 2; }
if(mkuItem == ModItems.syringe_metal_empty) { key = "book_syringe"; pages = 2; }
if(key == null) return new ItemStack(ModItems.flame_pony);
int s = 1;
for(int i = 0; i < 9; i++) {
if(recipe[i] != null && recipe[i].getItem() == mkuItem) {
s = i + 1; break;
}
}
ItemStack book = ItemBookLore.createBook(key, pages, 0x271E44, 0xFBFFF4);
ItemBookLore.addArgs(book, pages - 1, String.valueOf(s));
return book;
}
@Override @Override
public int getRecipeSize() { public int getRecipeSize() {
return 6; return 6;

View File

@ -1,7 +1,156 @@
package com.hbm.items.tool; package com.hbm.items.tool;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.hbm.blocks.ModBlocks;
import com.hbm.util.BobMathUtil;
import com.hbm.util.Tuple.Pair;
import com.hbm.world.gen.NBTStructure;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
public class ItemWandS extends Item { public class ItemWandS extends Item {
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
list.add("Creative-only item");
list.add("\"Replication breeds decadence\"");
list.add("(Saves an area defined by two right-clicks,");
list.add("adds a block to the blacklist by crouch right-clicking!)");
if(stack.stackTagCompound != null) {
int px = stack.stackTagCompound.getInteger("x");
int py = stack.stackTagCompound.getInteger("y");
int pz = stack.stackTagCompound.getInteger("z");
if(px != 0 || py != 0 || pz != 0) {
list.add(EnumChatFormatting.AQUA + "From: " + px + ", " + py + ", " + pz);
} else {
list.add(EnumChatFormatting.AQUA + "No start position set");
}
Set<Pair<Block, Integer>> blocks = getBlocks(stack);
if(blocks.size() > 0) {
list.add("Blacklist:");
for(Pair<Block, Integer> block : blocks) {
list.add(EnumChatFormatting.RED + "- " + block.key.getUnlocalizedName());
}
}
}
}
// why the fuck ye'd leave this whole thing obfuscated is beyond me
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float fx, float fy, float fz) {
if(stack.stackTagCompound == null) {
stack.stackTagCompound = new NBTTagCompound();
}
if(player.isSneaking()) {
Pair<Block, Integer> target = new Pair<Block, Integer>(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z));
Set<Pair<Block, Integer>> blocks = getBlocks(stack);
if(blocks.contains(target)) {
blocks.remove(target);
if(world.isRemote) player.addChatMessage(new ChatComponentText("Removed from blacklist " + target.key.getUnlocalizedName()));
} else {
blocks.add(target);
if(world.isRemote) player.addChatMessage(new ChatComponentText("Added to blacklist " + target.key.getUnlocalizedName()));
}
setBlocks(stack, blocks);
} else {
int px = stack.stackTagCompound.getInteger("x");
int py = stack.stackTagCompound.getInteger("y");
int pz = stack.stackTagCompound.getInteger("z");
if(px == 0 && py == 0 && pz == 0) {
setPosition(stack, x, y, z);
if(world.isRemote) player.addChatMessage(new ChatComponentText("First position set!"));
} else {
setPosition(stack, 0, 0, 0);
Set<Pair<Block, Integer>> blocks = getBlocks(stack);
blocks.add(new Pair<Block, Integer>(Blocks.air, 0));
blocks.add(new Pair<Block, Integer>(ModBlocks.spotlight_beam, 0));
String filename = "structure_" + dateFormat.format(new Date()).toString() + ".nbt";
NBTStructure.saveArea(filename, world, x, y, z, px, py, pz, blocks);
if(world.isRemote) player.addChatMessage(new ChatComponentText("Structure saved to: .minecraft/structures/" + filename));
}
}
return true;
}
private void setPosition(ItemStack stack, int x, int y, int z) {
stack.stackTagCompound.setInteger("x", x);
stack.stackTagCompound.setInteger("y", y);
stack.stackTagCompound.setInteger("z", z);
}
private Set<Pair<Block, Integer>> getBlocks(ItemStack stack) {
if(stack.stackTagCompound == null) {
return new HashSet<>();
}
int[] blockIds = stack.stackTagCompound.getIntArray("blocks");
int[] metas = stack.stackTagCompound.getIntArray("metas");
Set<Pair<Block, Integer>> blocks = new HashSet<>(blockIds.length);
for(int i = 0; i < blockIds.length; i++) {
blocks.add(new Pair<Block, Integer>(Block.getBlockById(blockIds[i]), metas[i]));
}
return blocks;
}
@SuppressWarnings("unchecked")
private void setBlocks(ItemStack stack, Set<Pair<Block, Integer>> blocks) {
if(stack.stackTagCompound == null) {
stack.stackTagCompound = new NBTTagCompound();
}
stack.stackTagCompound.setIntArray("blocks", BobMathUtil.collectionToIntArray(blocks, i -> Block.getIdFromBlock(((Pair<Block, Integer>)i).getKey())));
stack.stackTagCompound.setIntArray("metas", BobMathUtil.collectionToIntArray(blocks, i -> ((Pair<Block, Integer>)i).getValue()));
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(stack.stackTagCompound == null) {
stack.stackTagCompound = new NBTTagCompound();
}
if(player.isSneaking()) {
stack.stackTagCompound.setIntArray("blocks", new int[0]);
stack.stackTagCompound.setIntArray("metas", new int[0]);
if(world.isRemote) {
player.addChatMessage(new ChatComponentText("Cleared blacklist"));
}
}
return stack;
}
} }

View File

@ -1,6 +1,7 @@
package com.hbm.lib; package com.hbm.lib;
import com.hbm.world.gen.MapGenNTMFeatures; import com.hbm.world.gen.MapGenNTMFeatures;
import com.hbm.world.gen.NBTStructure;
import com.hbm.world.gen.NTMWorldGenerator; import com.hbm.world.gen.NTMWorldGenerator;
import com.hbm.world.gen.component.*; import com.hbm.world.gen.component.*;
import com.hbm.world.gen.component.BunkerComponents.BunkerStart; import com.hbm.world.gen.component.BunkerComponents.BunkerStart;
@ -18,9 +19,6 @@ public class HbmWorld {
public static NTMWorldGenerator worldGenerator; public static NTMWorldGenerator worldGenerator;
public static void initWorldGen() { public static void initWorldGen() {
//MapGenStructureIO.registerStructure(StructureStartTest.class, "HFR_STRUCTURE");
//MapGenStructureIO.func_143031_a(StructureComponentTest.class, "HFR_COMPONENT");
MapGenStructureIO.registerStructure(MapGenNTMFeatures.Start.class, "NTMFeatures"); MapGenStructureIO.registerStructure(MapGenNTMFeatures.Start.class, "NTMFeatures");
MapGenStructureIO.registerStructure(BunkerStart.class, "NTMBunker"); MapGenStructureIO.registerStructure(BunkerStart.class, "NTMBunker");
registerNTMFeatures(); registerNTMFeatures();
@ -30,15 +28,16 @@ public class HbmWorld {
worldGenerator = new NTMWorldGenerator(); worldGenerator = new NTMWorldGenerator();
registerWorldGen(worldGenerator, 1); //Ideally, move everything over from HbmWorldGen to NTMWorldGenerator registerWorldGen(worldGenerator, 1); //Ideally, move everything over from HbmWorldGen to NTMWorldGenerator
MinecraftForge.EVENT_BUS.register(worldGenerator); MinecraftForge.EVENT_BUS.register(worldGenerator);
//registerWorldGen(new WorldGenTest(), 1);
NBTStructure.register();
} }
public static void registerWorldGen(IWorldGenerator nukerWorldGen, int weightedProbability) { private static void registerWorldGen(IWorldGenerator nukerWorldGen, int weightedProbability) {
GameRegistry.registerWorldGenerator(nukerWorldGen, weightedProbability); GameRegistry.registerWorldGenerator(nukerWorldGen, weightedProbability);
} }
/** Register structures in MapGenStructureIO */ /** Register structures in MapGenStructureIO */
public static void registerNTMFeatures() { private static void registerNTMFeatures() {
CivilianFeatures.registerComponents(); CivilianFeatures.registerComponents();
OfficeFeatures.registerComponents(); OfficeFeatures.registerComponents();
RuinFeatures.registerComponents(); RuinFeatures.registerComponents();

View File

@ -545,37 +545,6 @@ public class HbmWorldGen implements IWorldGenerator {
} }
if (WorldConfig.meteorStructure > 0 && rand.nextInt(WorldConfig.meteorStructure) == 0 && biome != BiomeGenBase.ocean && biome != BiomeGenBase.deepOcean) {
int x = i + rand.nextInt(16) + 8;
int z = j + rand.nextInt(16) + 8;
CellularDungeonFactory.meteor.generate(world, x, 10, z, rand);
if(GeneralConfig.enableDebugMode)
MainRegistry.logger.info("[Debug] Successfully spawned meteor dungeon at " + x + " 10 " + z);
int y = world.getHeightValue(x, z);
for(int f = 0; f < 3; f++)
world.setBlock(x, y + f, z, ModBlocks.meteor_pillar);
world.setBlock(x, y + 3, z, ModBlocks.meteor_brick_chiseled);
for(int f = 0; f < 10; f++) {
x = i + rand.nextInt(65) - 32;
z = j + rand.nextInt(65) - 32;
y = world.getHeightValue(x, z);
if(world.getBlock(x, y - 1, z).canPlaceTorchOnTop(world, x, y - 1, z)) {
world.setBlock(x, y, z, Blocks.skull, 1, 2);
TileEntitySkull skull = (TileEntitySkull)world.getTileEntity(x, y, z);
if(skull != null)
skull.func_145903_a(rand.nextInt(16));
}
}
}
if((biome == BiomeGenBase.jungle || biome == BiomeGenBase.jungleEdge || biome == BiomeGenBase.jungleHills) && if((biome == BiomeGenBase.jungle || biome == BiomeGenBase.jungleEdge || biome == BiomeGenBase.jungleHills) &&
WorldConfig.jungleStructure > 0 && rand.nextInt(WorldConfig.jungleStructure) == 0) { WorldConfig.jungleStructure > 0 && rand.nextInt(WorldConfig.jungleStructure) == 0) {
int x = i + rand.nextInt(16); int x = i + rand.nextInt(16);

View File

@ -831,6 +831,8 @@ public class ClientProxy extends ServerProxy {
RenderingRegistry.registerBlockHandler(new RenderRBMKReflector()); RenderingRegistry.registerBlockHandler(new RenderRBMKReflector());
RenderingRegistry.registerBlockHandler(new RenderRBMKControl()); RenderingRegistry.registerBlockHandler(new RenderRBMKControl());
RenderingRegistry.registerBlockHandler(new RenderPribris()); RenderingRegistry.registerBlockHandler(new RenderPribris());
RenderingRegistry.registerBlockHandler(new RenderBlockWand());
} }
@Override @Override

View File

@ -0,0 +1,63 @@
package com.hbm.main;
import com.hbm.lib.RefStrings;
import com.hbm.world.gen.NBTStructure;
import net.minecraft.util.ResourceLocation;
public class StructureManager {
// METEOR DUNGEON
public static final NBTStructure meteor_spike = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/meteor-spike.nbt"));
public static final NBTStructure meteor_core = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/meteor-core.nbt"));
public static final NBTStructure meteor_corner = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/meteor-corner.nbt"));
public static final NBTStructure meteor_t = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/meteor-t.nbt"));
public static final NBTStructure meteor_stairs = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/meteor-stairs.nbt"));
public static final NBTStructure meteor_fallback = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/meteor-fallback.nbt"));
public static final NBTStructure meteor_3_bale = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-bale.nbt"));
public static final NBTStructure meteor_3_blank = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-blank.nbt"));
public static final NBTStructure meteor_3_block = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-block.nbt"));
public static final NBTStructure meteor_3_crab = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-crab.nbt"));
public static final NBTStructure meteor_3_crab_tesla = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-crab-tesla.nbt"));
public static final NBTStructure meteor_3_crate = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-crate.nbt"));
public static final NBTStructure meteor_3_dirt = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-dirt.nbt"));
public static final NBTStructure meteor_3_lead = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-lead.nbt"));
public static final NBTStructure meteor_3_ooze = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-ooze.nbt"));
public static final NBTStructure meteor_3_pillar = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-pillar.nbt"));
public static final NBTStructure meteor_3_star = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-star.nbt"));
public static final NBTStructure meteor_3_tesla = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-tesla.nbt"));
public static final NBTStructure meteor_3_book = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-book.nbt"));
public static final NBTStructure meteor_3_mku = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-mku.nbt"));
public static final NBTStructure meteor_3_statue = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/loot3x3/meteor-3-statue.nbt"));
public static final NBTStructure meteor_room_base_end = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-base-end.nbt"));
public static final NBTStructure meteor_room_base_thru = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-base-thru.nbt"));
public static final NBTStructure meteor_room_balcony = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-balcony.nbt"));
public static final NBTStructure meteor_room_basic = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-basic.nbt"));
public static final NBTStructure meteor_room_dragon = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-dragon.nbt"));
public static final NBTStructure meteor_room_ladder = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-ladder.nbt"));
public static final NBTStructure meteor_room_ooze = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-ooze.nbt"));
public static final NBTStructure meteor_room_split = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-split.nbt"));
public static final NBTStructure meteor_room_stairs = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-stairs.nbt"));
public static final NBTStructure meteor_room_triple = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-triple.nbt"));
public static final NBTStructure meteor_room_fallback = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/room-fallback.nbt"));
public static final NBTStructure meteor_dragon_chest = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/headloot/loot-chest.nbt"));
public static final NBTStructure meteor_dragon_tesla = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/headloot/loot-tesla.nbt"));
public static final NBTStructure meteor_dragon_trap = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/headloot/loot-trap.nbt"));
public static final NBTStructure meteor_dragon_crate_crab = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/meteor/room10/headloot/loot-crate-crab.nbt"));
public static final NBTStructure vertibird = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/vertibird.nbt"));
public static final NBTStructure crashed_vertibird = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/crashed-vertibird.nbt"));
// public static final NBTStructure test_rot = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/test-rot.nbt"));
// public static final NBTStructure test_jigsaw = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/test-jigsaw.nbt"));
// public static final NBTStructure test_jigsaw_core = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/test-jigsaw-core.nbt"));
// public static final NBTStructure test_jigsaw_hall = new NBTStructure(new ResourceLocation(RefStrings.MODID, "structures/test-jigsaw-hall.nbt"));
}

View File

@ -0,0 +1,37 @@
package com.hbm.render.block;
import com.hbm.blocks.generic.BlockWand;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
public class RenderBlockWand implements ISimpleBlockRenderingHandler {
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
renderer.renderFromInside = true;
renderer.renderStandardBlock(block, x, y, z);
renderer.renderFromInside = false;
renderer.renderStandardBlock(block, x, y, z);
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return false;
}
@Override
public int getRenderId() {
return BlockWand.renderID;
}
}

View File

@ -15,6 +15,8 @@ import com.hbm.blocks.generic.BlockPedestal.TileEntityPedestal;
import com.hbm.blocks.generic.BlockPlushie.TileEntityPlushie; import com.hbm.blocks.generic.BlockPlushie.TileEntityPlushie;
import com.hbm.blocks.generic.BlockSnowglobe.TileEntitySnowglobe; import com.hbm.blocks.generic.BlockSnowglobe.TileEntitySnowglobe;
import com.hbm.blocks.generic.BlockSupplyCrate.TileEntitySupplyCrate; import com.hbm.blocks.generic.BlockSupplyCrate.TileEntitySupplyCrate;
import com.hbm.blocks.generic.BlockWandJigsaw.TileEntityWandJigsaw;
import com.hbm.blocks.generic.BlockWandLoot.TileEntityWandLoot;
import com.hbm.blocks.generic.PartEmitter.TileEntityPartEmitter; import com.hbm.blocks.generic.PartEmitter.TileEntityPartEmitter;
import com.hbm.blocks.machine.BlockICF.TileEntityBlockICF; import com.hbm.blocks.machine.BlockICF.TileEntityBlockICF;
import com.hbm.blocks.machine.BlockPWR.TileEntityBlockPWR; import com.hbm.blocks.machine.BlockPWR.TileEntityBlockPWR;
@ -233,6 +235,9 @@ public class TileMappings {
put(TileEntityData.class, "tileentity_data"); put(TileEntityData.class, "tileentity_data");
put(TileEntityWandLoot.class, "tileentity_wand_loot");
put(TileEntityWandJigsaw.class, "tileentity_wand_jigsaw");
putNetwork(); putNetwork();
putBombs(); putBombs();
putTurrets(); putTurrets();

View File

@ -2,6 +2,7 @@ package com.hbm.util;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockLoot.TileEntityLoot; import com.hbm.blocks.generic.BlockLoot.TileEntityLoot;
import com.hbm.crafting.handlers.MKUCraftingHandler;
import com.hbm.inventory.OreDictManager.DictFrame; import com.hbm.inventory.OreDictManager.DictFrame;
import com.hbm.itempool.ItemPool; import com.hbm.itempool.ItemPool;
import com.hbm.itempool.ItemPoolsPile; import com.hbm.itempool.ItemPoolsPile;
@ -10,6 +11,7 @@ import com.hbm.items.special.ItemBookLore;
import com.hbm.items.weapon.sedna.factory.GunFactory.EnumAmmo; import com.hbm.items.weapon.sedna.factory.GunFactory.EnumAmmo;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -17,6 +19,45 @@ import java.util.Random;
public class LootGenerator { public class LootGenerator {
public static final String LOOT_BOOKLET = "LOOT_BOOKLET";
public static final String LOOT_CAPNUKE = "LOOT_CAPNUKE";
public static final String LOOT_MEDICINE = "LOOT_MEDICINE";
public static final String LOOT_CAPSTASH = "LOOT_CAPSTASH";
public static final String LOOT_MAKESHIFT_GUN = "LOOT_MAKESHIFT_GUN";
public static final String LOOT_NUKE_STORAGE = "LOOT_NUKE_STORAGE";
public static final String LOOT_BONES = "LOOT_BONES";
public static final String LOOT_GLYPHID_HIVE = "LOOT_GLYPHID_HIVE";
public static final String LOOT_METEOR = "LOOT_METEOR";
public static void applyLoot(World world, int x, int y, int z, String name) {
switch(name) {
case LOOT_BOOKLET: lootBooklet(world, x, y, z);
case LOOT_CAPNUKE: lootCapNuke(world, x, y, z);
case LOOT_MEDICINE: lootMedicine(world, x, y, z);
case LOOT_CAPSTASH: lootCapStash(world, x, y, z);
case LOOT_MAKESHIFT_GUN: lootMakeshiftGun(world, x, y, z);
case LOOT_NUKE_STORAGE: lootNukeStorage(world, x, y, z);
case LOOT_BONES: lootBones(world, x, y, z);
case LOOT_GLYPHID_HIVE: lootGlyphidHive(world, x, y, z);
case LOOT_METEOR: lootBookMeteor(world, x, y, z);
default: lootBones(world, x, y, z); break;
}
}
public static String[] getLootNames() {
return new String[] {
LOOT_BOOKLET,
LOOT_CAPNUKE,
LOOT_MEDICINE,
LOOT_CAPSTASH,
LOOT_MAKESHIFT_GUN,
LOOT_NUKE_STORAGE,
LOOT_BONES,
LOOT_GLYPHID_HIVE,
LOOT_METEOR,
};
}
public static void setBlock(World world, int x, int y, int z) { public static void setBlock(World world, int x, int y, int z) {
world.setBlock(x, y, z, ModBlocks.deco_loot); world.setBlock(x, y, z, ModBlocks.deco_loot);
} }
@ -142,6 +183,19 @@ public class LootGenerator {
} }
} }
public static void lootBookMeteor(World world, int x, int y, int z) {
TileEntityLoot loot = (TileEntityLoot) world.getTileEntity(x, y, z);
if(loot != null && loot.items.isEmpty()) {
Item mkuItem = MKUCraftingHandler.getMKUItem(world);
ItemStack mkuBook = MKUCraftingHandler.generateBook(world, mkuItem);
addItemWithDeviation(loot, world.rand, new ItemStack(mkuItem), 0, 0, 0.25);
addItemWithDeviation(loot, world.rand, mkuBook, 0, 0, -0.25);
}
}
public static void lootBookLore(World world, int x, int y, int z, ItemStack book) { public static void lootBookLore(World world, int x, int y, int z, ItemStack book) {
TileEntityLoot loot = (TileEntityLoot) world.getTileEntity(x, y, z); TileEntityLoot loot = (TileEntityLoot) world.getTileEntity(x, y, z);

View File

@ -0,0 +1,14 @@
package com.hbm.world.gen;
import net.minecraft.world.World;
public interface INBTTileEntityTransformable {
/**
* Like INBTTransformable but for TileEntities, like for randomizing bobbleheads
*/
// Allows for the TE to modify itself when spawned in an NBT structure
public void transformTE(World world, int coordBaseMode);
}

View File

@ -0,0 +1,161 @@
package com.hbm.world.gen;
import net.minecraft.block.Block;
public interface INBTTransformable {
/**
* Defines this block as something that has a rotation or some other blockstate
* which needs transformations applied when building from an .nbt structure file
*/
// Takes the block current meta and translates it into a rotated meta
public int transformMeta(int meta, int coordBaseMode);
// Takes the block and turns it into a different block entirely, to turn off lights, shit like that
public default Block transformBlock(Block block) {
return block;
}
/**
* A fair few blocks have generalized rotations so, since we have all this space, put em here
*/
public static int transformMetaDeco(int meta, int coordBaseMode) {
switch(coordBaseMode) {
case 1: //West
switch(meta) {
case 2: return 5;
case 3: return 4;
case 4: return 2;
case 5: return 3;
}
case 2: //North
switch(meta) {
case 2: return 3;
case 3: return 2;
case 4: return 5;
case 5: return 4;
}
case 3: //East
switch(meta) {
case 2: return 4;
case 3: return 5;
case 4: return 3;
case 5: return 2;
}
}
return meta;
}
public static int transformMetaDecoModel(int meta, int coordBaseMode) {
int rot = (meta + coordBaseMode) % 4;
int type = (meta / 4) * 4;
return rot | type;
}
public static int transformMetaStairs(int meta, int coordBaseMode) {
switch(coordBaseMode) {
case 1: //West
if((meta & 3) < 2) //Flip second bit for E/W
meta = meta ^ 2;
else
meta = meta ^ 3; //Flip both bits for N/S
break;
case 2: //North
meta = meta ^ 1; //Flip first bit
break;
case 3: //East
if((meta & 3) < 2) //Flip both bits for E/W
meta = meta ^ 3;
else //Flip second bit for N/S
meta = meta ^ 2;
break;
}
return meta;
}
public static int transformMetaPillar(int meta, int coordBaseMode) {
if(coordBaseMode == 2) return meta;
int type = meta & 3;
int rot = meta & 12;
if(rot == 4) return type | 8;
if(rot == 8) return type | 4;
return meta;
}
public static int transformMetaDirectional(int meta, int coordBaseMode) {
int rot = meta & 3;
int other = meta & 12;
switch(coordBaseMode) {
default: //S
break;
case 1: //W
rot = (rot + 1) % 4; break;
case 2: //N
rot ^= 2; break;
case 3: //E
rot = (rot + 3) % 4; break;
}
return other | rot;
}
public static int transformMetaTorch(int meta, int coordBaseMode) {
switch(coordBaseMode) {
case 1: //West
switch(meta) {
case 1: return 3;
case 2: return 4;
case 3: return 2;
case 4: return 1;
}
case 2: //North
switch(meta) {
case 1: return 2;
case 2: return 1;
case 3: return 4;
case 4: return 3;
}
case 3: //East
switch(meta) {
case 1: return 4;
case 2: return 3;
case 3: return 1;
case 4: return 2;
}
}
return meta;
}
public static int transformMetaDoor(int meta, int coordBaseMode) {
if(meta == 8 || meta == 9) return meta; // ignore top parts
return transformMetaDirectional(meta, coordBaseMode);
}
public static int transformMetaLever(int meta, int coordBaseMode) {
if(meta <= 0 || meta >= 7) { //levers suck ass
switch(coordBaseMode) {
case 1: case 3: //west / east
meta ^= 0b111;
}
} else if(meta >= 5) {
switch(coordBaseMode) {
case 1: case 3: //west / east
meta = (meta + 1) % 2 + 5;
}
} else {
meta = transformMetaTorch(meta, coordBaseMode);
}
return meta;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,22 @@
package com.hbm.world.gen; package com.hbm.world.gen;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.StructureConfig; import com.hbm.config.StructureConfig;
import com.hbm.main.StructureManager;
import com.hbm.world.gen.NBTStructure.JigsawPiece;
import com.hbm.world.gen.NBTStructure.JigsawPool;
import com.hbm.world.gen.NBTStructure.SpawnCondition;
import com.hbm.world.gen.component.BunkerComponents.BunkerStart;
import com.hbm.world.gen.component.Component.CrabSpawners;
import com.hbm.world.gen.component.Component.GreenOoze;
import com.hbm.world.gen.component.Component.MeteorBricks;
import com.hbm.world.gen.component.Component.SupplyCrates;
import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -10,28 +24,124 @@ import net.minecraft.block.Block;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import static net.minecraftforge.common.BiomeDictionary.*; import net.minecraft.world.gen.structure.StructureComponent.BlockSelector;
import net.minecraftforge.event.terraingen.InitMapGenEvent.EventType; import net.minecraftforge.event.terraingen.InitMapGenEvent.EventType;
import net.minecraftforge.event.terraingen.PopulateChunkEvent; import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import static net.minecraftforge.event.terraingen.TerrainGen.*; import net.minecraftforge.event.terraingen.TerrainGen;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
public class NTMWorldGenerator implements IWorldGenerator { public class NTMWorldGenerator implements IWorldGenerator {
private MapGenNTMFeatures scatteredFeatureGen = new MapGenNTMFeatures();
boolean regTest = false;
public NTMWorldGenerator() {
final List<BiomeGenBase> invalidBiomes = Arrays.asList(new BiomeGenBase[] {BiomeGenBase.ocean, BiomeGenBase.river, BiomeGenBase.frozenOcean, BiomeGenBase.frozenRiver, BiomeGenBase.deepOcean});
NBTStructure.registerStructure(0, new SpawnCondition() {{
canSpawn = biome -> !invalidBiomes.contains(biome);
start = d -> new MapGenNTMFeatures.Start(d.getW(), d.getX(), d.getY(), d.getZ());
spawnWeight = 14;
}});
NBTStructure.registerStructure(0, new SpawnCondition() {{
canSpawn = biome -> !invalidBiomes.contains(biome);
start = d -> new BunkerStart(d.getW(), d.getX(), d.getY(), d.getZ());
spawnWeight = 1;
}});
Map<Block, BlockSelector> bricks = new HashMap<Block, BlockSelector>() {{
put(ModBlocks.meteor_brick, new MeteorBricks());
}};
Map<Block, BlockSelector> crates = new HashMap<Block, BlockSelector>() {{
put(ModBlocks.meteor_brick, new MeteorBricks());
put(ModBlocks.crate, new SupplyCrates());
put(ModBlocks.meteor_spawner, new CrabSpawners());
}};
Map<Block, BlockSelector> ooze = new HashMap<Block, BlockSelector>() {{
put(ModBlocks.meteor_brick, new MeteorBricks());
put(ModBlocks.concrete_colored, new GreenOoze());
}};
NBTStructure.registerStructure(0, new SpawnCondition() {{
minHeight = 32;
maxHeight = 32;
sizeLimit = 128;
canSpawn = biome -> biome.rootHeight >= 0;
startPool = "start";
pools = new HashMap<String, NBTStructure.JigsawPool>() {{
put("start", new JigsawPool() {{
add(new JigsawPiece("meteor_core", StructureManager.meteor_core) {{ blockTable = bricks; }}, 1);
}});
put("spike", new JigsawPool() {{
add(new JigsawPiece("meteor_spike", StructureManager.meteor_spike) {{ heightOffset = -3; conformToTerrain = true; }}, 1);
}});
put("default", new JigsawPool() {{
add(new JigsawPiece("meteor_corner", StructureManager.meteor_corner) {{ blockTable = bricks; }}, 2);
add(new JigsawPiece("meteor_t", StructureManager.meteor_t) {{ blockTable = bricks; }}, 3);
add(new JigsawPiece("meteor_stairs", StructureManager.meteor_stairs) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_base_thru", StructureManager.meteor_room_base_thru) {{ blockTable = bricks; }}, 3);
add(new JigsawPiece("meteor_room_base_end", StructureManager.meteor_room_base_end) {{ blockTable = bricks; }}, 4);
fallback = "fallback";
}});
put("10room", new JigsawPool() {{
add(new JigsawPiece("meteor_room_basic", StructureManager.meteor_room_basic) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_balcony", StructureManager.meteor_room_balcony) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_dragon", StructureManager.meteor_room_dragon) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_ladder", StructureManager.meteor_room_ladder) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_ooze", StructureManager.meteor_room_ooze) {{ blockTable = ooze; }}, 1);
add(new JigsawPiece("meteor_room_split", StructureManager.meteor_room_split) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_stairs", StructureManager.meteor_room_stairs) {{ blockTable = bricks; }}, 1);
add(new JigsawPiece("meteor_room_triple", StructureManager.meteor_room_triple) {{ blockTable = bricks; }}, 1);
fallback = "roomback";
}});
put("3x3loot", new JigsawPool() {{
add(new JigsawPiece("meteor_3_bale", StructureManager.meteor_3_bale), 1);
add(new JigsawPiece("meteor_3_blank", StructureManager.meteor_3_blank), 1);
add(new JigsawPiece("meteor_3_block", StructureManager.meteor_3_block), 1);
add(new JigsawPiece("meteor_3_crab", StructureManager.meteor_3_crab), 1);
add(new JigsawPiece("meteor_3_crab_tesla", StructureManager.meteor_3_crab_tesla), 1);
add(new JigsawPiece("meteor_3_crate", StructureManager.meteor_3_crate), 1);
add(new JigsawPiece("meteor_3_dirt", StructureManager.meteor_3_dirt), 1);
add(new JigsawPiece("meteor_3_lead", StructureManager.meteor_3_lead), 1);
add(new JigsawPiece("meteor_3_ooze", StructureManager.meteor_3_ooze), 1);
add(new JigsawPiece("meteor_3_pillar", StructureManager.meteor_3_pillar), 1);
add(new JigsawPiece("meteor_3_star", StructureManager.meteor_3_star), 1);
add(new JigsawPiece("meteor_3_tesla", StructureManager.meteor_3_tesla), 1);
add(new JigsawPiece("meteor_3_book", StructureManager.meteor_3_book), 1);
add(new JigsawPiece("meteor_3_mku", StructureManager.meteor_3_mku), 1);
add(new JigsawPiece("meteor_3_statue", StructureManager.meteor_3_statue), 1);
}});
put("headloot", new JigsawPool() {{
add(new JigsawPiece("meteor_dragon_chest", StructureManager.meteor_dragon_chest) {{ blockTable = crates; }}, 1);
add(new JigsawPiece("meteor_dragon_tesla", StructureManager.meteor_dragon_tesla) {{ blockTable = crates; }}, 1);
add(new JigsawPiece("meteor_dragon_trap", StructureManager.meteor_dragon_trap) {{ blockTable = crates; }}, 1);
add(new JigsawPiece("meteor_dragon_crate_crab", StructureManager.meteor_dragon_crate_crab) {{ blockTable = crates; }}, 1);
}});
put("fallback", new JigsawPool() {{
add(new JigsawPiece("meteor_fallback", StructureManager.meteor_fallback) {{ blockTable = bricks; }}, 1);
}});
put("roomback", new JigsawPool() {{
add(new JigsawPiece("meteor_room_fallback", StructureManager.meteor_room_fallback) {{ blockTable = bricks; }}, 1);
}});
}};
}});
}
private NBTStructure.GenStructure nbtGen = new NBTStructure.GenStructure();
private final Random rand = new Random(); //A central random, used to cleanly generate our stuff without affecting vanilla or modded seeds. private final Random rand = new Random(); //A central random, used to cleanly generate our stuff without affecting vanilla or modded seeds.
/** Inits all MapGen upon the loading of a new world. Hopefully clears out structureMaps and structureData when a different world is loaded. */ /** Inits all MapGen upon the loading of a new world. Hopefully clears out structureMaps and structureData when a different world is loaded. */
@SubscribeEvent @SubscribeEvent
public void onLoad(WorldEvent.Load event) { public void onLoad(WorldEvent.Load event) {
scatteredFeatureGen = (MapGenNTMFeatures) getModdedMapGen(new MapGenNTMFeatures(), EventType.CUSTOM); nbtGen = (NBTStructure.GenStructure) TerrainGen.getModdedMapGen(new NBTStructure.GenStructure(), EventType.CUSTOM);
hasPopulationEvent = false; hasPopulationEvent = false;
} }
/** Called upon the initial population of a chunk. Called in the pre-population event first; called again if pre-population didn't occur (flatland) */ /** Called upon the initial population of a chunk. Called in the pre-population event first; called again if pre-population didn't occur (flatland) */
private void setRandomSeed(World world, int chunkX, int chunkZ) { private void setRandomSeed(World world, int chunkX, int chunkZ) {
rand.setSeed(world.getSeed()); rand.setSeed(world.getSeed() + world.provider.dimensionId);
final long i = rand.nextLong() / 2L * 2L + 1L; final long i = rand.nextLong() / 2L * 2L + 1L;
final long j = rand.nextLong() / 2L * 2L + 1L; final long j = rand.nextLong() / 2L * 2L + 1L;
rand.setSeed((long)chunkX * i + (long)chunkZ * j ^ world.getSeed()); rand.setSeed((long)chunkX * i + (long)chunkZ * j ^ world.getSeed());
@ -46,28 +156,14 @@ public class NTMWorldGenerator implements IWorldGenerator {
@SubscribeEvent @SubscribeEvent
public void generateStructures(PopulateChunkEvent.Pre event) { public void generateStructures(PopulateChunkEvent.Pre event) {
setRandomSeed(event.world, event.chunkX, event.chunkZ); //Set random for population down the line.
hasPopulationEvent = true; hasPopulationEvent = true;
if(StructureConfig.enableStructures == 0) return; if(StructureConfig.enableStructures == 0) return;
if(StructureConfig.enableStructures == 2 && !event.world.getWorldInfo().isMapFeaturesEnabled()) return; if(StructureConfig.enableStructures == 2 && !event.world.getWorldInfo().isMapFeaturesEnabled()) return;
switch (event.world.provider.dimensionId) { setRandomSeed(event.world, event.chunkX, event.chunkZ); //Set random for population down the line.
case -1:
break;
case 0:
generateOverworldStructures(event.world, event.chunkProvider, event.chunkX, event.chunkZ);
break;
case 1:
break;
}
}
protected void generateOverworldStructures(World world, IChunkProvider chunkProvider, int chunkX, int chunkZ) { nbtGen.generateStructures(event.world, rand, event.chunkProvider, event.chunkX, event.chunkZ);
Block[] ablock = new Block[65536]; //ablock isn't actually used for anything in MapGenStructure
this.scatteredFeatureGen.func_151539_a(chunkProvider, world, chunkX, chunkZ, ablock);
this.scatteredFeatureGen.generateStructuresInChunk(world, rand, chunkX, chunkZ);
} }
/* /*
@ -76,59 +172,15 @@ public class NTMWorldGenerator implements IWorldGenerator {
*/ */
@Override @Override
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { public void generate(Random unusedRandom, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
if(hasPopulationEvent) return; //If we've failed to generate any structures (flatlands)
switch (world.provider.dimensionId) { if(StructureConfig.enableStructures == 0) return;
case -1: if(StructureConfig.enableStructures == 2 && !world.getWorldInfo().isMapFeaturesEnabled()) return;
generateNether(world, rand, chunkGenerator, chunkX, chunkZ); break;
case 0:
generateSurface(world, rand, chunkGenerator, chunkProvider, chunkX, chunkZ); break;
case 1:
generateEnd(world, rand, chunkGenerator, chunkX, chunkZ); break;
}
}
private void generateNether(World world, Random rand, IChunkProvider chunkGenerator, int chunkX, int chunkZ) { }
/* Overworld Generation */
private void generateSurface(World world, Random rand, IChunkProvider chunkGenerator, IChunkProvider chunkProvider, int chunkX, int chunkZ) {
if(!hasPopulationEvent) { //If we've failed to generate any structures (flatlands)
setRandomSeed(world, chunkX, chunkZ); //Reset the random seed to compensate setRandomSeed(world, chunkX, chunkZ); //Reset the random seed to compensate
boolean enableStructures = world.getWorldInfo().isMapFeaturesEnabled(); nbtGen.generateStructures(world, rand, chunkProvider, chunkX, chunkZ);
if(StructureConfig.enableStructures == 1) enableStructures = true;
if(StructureConfig.enableStructures == 0) enableStructures = false;
if(enableStructures) generateOverworldStructures(world, chunkGenerator, chunkX, chunkZ); //Do it through the post-population generation directly
} }
/* biome dictionary my beloved <3
* no check for tom here because the event handler already checks for decoration events, + this way they won't become permanently extinct.
*/
/* Biome check, followed by chance, followed by event (for compat, both intra- and inter- (in the case of Tom). */
}
private void generateEnd(World world, Random rand, IChunkProvider chunkGenerator, int chunkX, int chunkZ) { }
/** Utility method for biome checking multiple types exclusively. Not sure why it wasn't already present. */
public static boolean isBiomeOfTypes(BiomeGenBase biome, Type... types) { //If new biomes are implemented, move this to any biome-related utility class.
for(Type type : types) {
if(!isBiomeOfType(biome, type)) return false;
}
return true;
}
/** utility method, same as above but inclusive. useful for catch-alls, like the dirty glass structures have */
public static boolean doesBiomeHaveTypes(BiomeGenBase biome, Type... types) {
for(Type type : types) {
if(isBiomeOfType(biome, type)) return true;
}
return false;
}
} }

View File

@ -12,6 +12,7 @@ import com.hbm.tileentity.machine.TileEntityLockableBase;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -1053,4 +1054,70 @@ abstract public class Component extends StructureComponent {
} }
} }
public static class MeteorBricks extends BlockSelector {
@Override
public void selectBlocks(Random rand, int posX, int posY, int posZ, boolean notInterior) {
float chance = rand.nextFloat();
if(chance < 0.4F) {
this.field_151562_a = ModBlocks.meteor_brick;
} else if (chance < 0.7F) {
this.field_151562_a = ModBlocks.meteor_brick_mossy;
} else {
this.field_151562_a = ModBlocks.meteor_brick_cracked;
}
}
}
public static class SupplyCrates extends BlockSelector {
@Override
public void selectBlocks(Random rand, int posX, int posY, int posZ, boolean notInterior) {
float chance = rand.nextFloat();
if(chance < 0.6F) {
this.field_151562_a = Blocks.air;
} else if(chance < 0.8F) {
this.field_151562_a = ModBlocks.crate_ammo;
} else if(chance < 0.9F) {
this.field_151562_a = ModBlocks.crate_can;
} else {
this.field_151562_a = ModBlocks.crate;
}
}
}
public static class CrabSpawners extends BlockSelector {
@Override
public void selectBlocks(Random rand, int posX, int posY, int posZ, boolean notInterior) {
float chance = rand.nextFloat();
if(chance < 0.8F) {
this.field_151562_a = ModBlocks.meteor_brick;
} else {
this.field_151562_a = ModBlocks.meteor_spawner;
}
}
}
public static class GreenOoze extends BlockSelector {
@Override
public void selectBlocks(Random rand, int posX, int posY, int posZ, boolean notInterior) {
float chance = rand.nextFloat();
if(chance < 0.8F) {
this.field_151562_a = ModBlocks.toxic_block;
} else {
this.field_151562_a = ModBlocks.meteor_polished;
}
}
}
} }

View File

@ -5329,6 +5329,7 @@ tile.deco_computer.ibm_300pl.name=IBM Personal Computer 300PL
tile.deco_crt.name=Old CRT Screen tile.deco_crt.name=Old CRT Screen
tile.deco_emitter.name=Deco Light Emitter tile.deco_emitter.name=Deco Light Emitter
tile.deco_lead.name=Lead Deco Block tile.deco_lead.name=Lead Deco Block
tile.deco_loot.name=Loot Pile
tile.deco_rbmk.name=RBMK Deco Block tile.deco_rbmk.name=RBMK Deco Block
tile.deco_rbmk_smooth.name=Smooth RBMK Deco Block tile.deco_rbmk_smooth.name=Smooth RBMK Deco Block
tile.deco_red_copper.name=Red Copper Deco Block tile.deco_red_copper.name=Red Copper Deco Block
@ -6151,6 +6152,9 @@ tile.vitrified_barrel.name=Vitrified Nuclear Waste Drum
tile.volcanic_lava_block.name=Volcanic Lava tile.volcanic_lava_block.name=Volcanic Lava
tile.volcano_core.name=Volcano Core tile.volcano_core.name=Volcano Core
tile.volcano_rad_core.name=Rad Volcano Core tile.volcano_rad_core.name=Rad Volcano Core
tile.wand_air.name=Structure Wand Block (Air)
tile.wand_loot.name=Structure Wand Block (Lootable)
tile.wand_jigsaw.name=Structure Wand Block (Jigsaw)
tile.waste_earth.name=Dead Grass tile.waste_earth.name=Dead Grass
tile.waste_leaves.name=Dead Leaves tile.waste_leaves.name=Dead Leaves
tile.waste_log.name=Charred Log tile.waste_log.name=Charred Log

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB