mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
250 lines
8.2 KiB
Java
250 lines
8.2 KiB
Java
package com.hbm.blocks.generic;
|
|
|
|
import api.hbm.block.IToolable;
|
|
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.interfaces.IBomb;
|
|
import com.hbm.interfaces.ICopiable;
|
|
import com.hbm.lib.RefStrings;
|
|
import com.hbm.main.MainRegistry;
|
|
import com.hbm.tileentity.TileEntityLoadedBase;
|
|
import com.hbm.util.BufferUtil;
|
|
import com.hbm.util.i18n.I18nUtil;
|
|
import com.hbm.world.gen.INBTTileEntityTransformable;
|
|
import com.hbm.world.gen.util.DungeonSpawnerActions;
|
|
import com.hbm.world.gen.util.DungeonSpawnerConditions;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.block.BlockContainer;
|
|
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.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.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IToolable, ITooltipProvider, IBlockSideRotation, IBomb {
|
|
|
|
@SideOnly(Side.CLIENT) protected IIcon iconTop;
|
|
|
|
public BlockWandSpawner() {
|
|
super(Material.iron);
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerBlockIcons(IIconRegister iconRegister) {
|
|
this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":wand_spawner");
|
|
this.iconTop = iconRegister.registerIcon(RefStrings.MODID + ":wand_spawner_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 TileEntityWandSpawner)
|
|
((TileEntityWandSpawner)te).placedRotation = i;
|
|
}
|
|
|
|
@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 TileEntityWandSpawner)) return false;
|
|
|
|
TileEntityWandSpawner spawner = (TileEntityWandSpawner) te;
|
|
|
|
switch(tool) {
|
|
case SCREWDRIVER:
|
|
List<String> actionNames = DungeonSpawnerActions.getActionNames();
|
|
int indexA = actionNames.indexOf(spawner.actionID);
|
|
|
|
indexA += player.isSneaking() ? -1 : 1;
|
|
indexA = MathHelper.clamp_int(indexA, 0, actionNames.size() - 1);
|
|
|
|
spawner.actionID = actionNames.get(indexA);
|
|
return true;
|
|
case DEFUSER:
|
|
List<String> conditionNames = DungeonSpawnerConditions.getConditionNames();
|
|
int indexC = conditionNames.indexOf(spawner.conditionID);
|
|
|
|
indexC += player.isSneaking() ? -1 : 1;
|
|
indexC = MathHelper.clamp_int(indexC, 0, conditionNames.size() - 1);
|
|
|
|
spawner.conditionID = conditionNames.get(indexC);
|
|
|
|
return true;
|
|
|
|
default: return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void printHook(RenderGameOverlayEvent.Pre event, World world, int x, int y, int z) {
|
|
TileEntity te = world.getTileEntity(x, y, z);
|
|
|
|
if(!(te instanceof TileEntityWandSpawner)) return;
|
|
|
|
TileEntityWandSpawner spawner = (TileEntityWandSpawner) te;
|
|
|
|
List<String> text = new ArrayList<String>();
|
|
text.add("Action: " + spawner.actionID);
|
|
text.add("Condition: " + spawner.conditionID);
|
|
|
|
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
|
|
}
|
|
|
|
@Override
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
|
|
list.add(EnumChatFormatting.GOLD + "Use screwdriver to cycle forwards through the action list, shift click to go back");
|
|
list.add(EnumChatFormatting.GOLD + "Use defuser to cycle forwards through the condition list, shift click to go back");
|
|
list.add(EnumChatFormatting.BLUE + "Use a detonator to transform");
|
|
}
|
|
|
|
@Override
|
|
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
|
return new TileEntityWandSpawner();
|
|
}
|
|
|
|
@Override
|
|
public BombReturnCode explode(World world, int x, int y, int z) {
|
|
TileEntity te = world.getTileEntity(x, y, z);
|
|
|
|
if(!(te instanceof TileEntityWandSpawner)) return null;
|
|
|
|
((TileEntityWandSpawner) te).triggerReplace = true;
|
|
|
|
return BombReturnCode.TRIGGERED;
|
|
}
|
|
|
|
public static class TileEntityWandSpawner extends TileEntityLoadedBase implements INBTTileEntityTransformable, ICopiable {
|
|
private boolean triggerReplace;
|
|
|
|
public int placedRotation;
|
|
|
|
public String actionID = "PHASE_ABERRATOR";
|
|
public String conditionID = "ABERRATOR";
|
|
|
|
@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() {
|
|
if (!(worldObj.getBlock(xCoord, yCoord, zCoord) instanceof BlockWandSpawner)) {
|
|
MainRegistry.logger.warn("Somehow the block at: " + xCoord + ", " + yCoord + ", " + zCoord + " isn't a dungeon spawner block but we're doing a TE update as if it is, cancelling!");
|
|
return;
|
|
}
|
|
worldObj.setBlock(xCoord,yCoord,zCoord, ModBlocks.dungeon_spawner);
|
|
|
|
TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord);
|
|
|
|
if(te == null || te instanceof BlockWandLoot.TileEntityWandLoot) {
|
|
MainRegistry.logger.warn("TE for dungeon spawner set incorrectly at: " + xCoord + ", " + yCoord + ", " + zCoord + ". If you're using some sort of world generation mod, report it to the author!");
|
|
te = ModBlocks.wand_spawner.createTileEntity(worldObj, 0);
|
|
worldObj.setTileEntity(xCoord, yCoord, zCoord, te);
|
|
}
|
|
|
|
if(te instanceof DungeonSpawner.TileEntityDungeonSpawner){
|
|
DungeonSpawner.TileEntityDungeonSpawner spawner = (DungeonSpawner.TileEntityDungeonSpawner) te;
|
|
spawner.actionID = actionID;
|
|
spawner.conditionID = conditionID;
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void transformTE(World world, int coordBaseMode) {
|
|
triggerReplace = !StructureConfig.debugStructures;
|
|
}
|
|
|
|
@Override
|
|
public void writeToNBT(NBTTagCompound nbt) {
|
|
super.writeToNBT(nbt);
|
|
nbt.setString("actionID", actionID);
|
|
nbt.setString("conditionID", conditionID);
|
|
nbt.setInteger("rotation", placedRotation);
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbt) {
|
|
super.readFromNBT(nbt);
|
|
actionID = nbt.getString("actionID");
|
|
conditionID = nbt.getString("conditionID");
|
|
placedRotation = nbt.getInteger("rotation");
|
|
}
|
|
|
|
@Override
|
|
public void serialize(ByteBuf buf) {
|
|
buf.writeInt(placedRotation);
|
|
BufferUtil.writeString(buf, actionID);
|
|
BufferUtil.writeString(buf, conditionID);
|
|
}
|
|
|
|
@Override
|
|
public void deserialize(ByteBuf buf) {
|
|
placedRotation = buf.readInt();
|
|
actionID = BufferUtil.readString(buf);
|
|
conditionID = BufferUtil.readString(buf);
|
|
}
|
|
|
|
@Override
|
|
public NBTTagCompound getSettings(World world, int x, int y, int z) {
|
|
NBTTagCompound nbt = new NBTTagCompound();
|
|
nbt.setString("actionID", actionID);
|
|
nbt.setString("conditionID", conditionID);
|
|
return nbt;
|
|
}
|
|
|
|
@Override
|
|
public void pasteSettings(NBTTagCompound nbt, int index, World world, EntityPlayer player, int x, int y, int z) {
|
|
actionID = nbt.getString("actionID");
|
|
conditionID = nbt.getString("conditionID");
|
|
}
|
|
}
|
|
}
|