mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
More work on powered spawner.
This commit is contained in:
1 parent
0d7d60a19a
commit
3182f4a4a8
12 files changed
+359
-45
No files matched your search
@@ -64,6 +64,7 @@ import crazypants.enderio.machine.power.CapBankRenderer2;
|
||||
import crazypants.enderio.machine.power.CapacitorBankRenderer;
|
||||
import crazypants.enderio.machine.reservoir.ReservoirRenderer;
|
||||
import crazypants.enderio.machine.reservoir.TileReservoir;
|
||||
import crazypants.enderio.machine.spawner.BrokenSpawnerRenderer;
|
||||
import crazypants.enderio.machine.still.BlockVat;
|
||||
import crazypants.enderio.machine.still.VatRenderer;
|
||||
import crazypants.enderio.machine.tank.TankFluidRenderer;
|
||||
@@ -144,6 +145,8 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockPainter), machRen);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCrafter), machRen);
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(EnderIO.itemBrokenSpawner, new BrokenSpawnerRenderer());
|
||||
|
||||
|
||||
BlockFusedQuartz.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(new FusedQuartzRenderer());
|
||||
|
||||
@@ -153,11 +153,13 @@ public final class Config {
|
||||
|
||||
public static int poweredSpawnerMinDelayTicks = 200;
|
||||
public static int poweredSpawnerMaxDelayTicks = 800;
|
||||
public static float poweredSpawnerLevelOnePowerPerTick = 4;
|
||||
public static float poweredSpawnerLevelTwoPowerPerTick = 16;
|
||||
public static float poweredSpawnerLevelThreePowerPerTick = 64;
|
||||
public static float poweredSpawnerLevelOnePowerPerTick = 16;
|
||||
public static float poweredSpawnerLevelTwoPowerPerTick = 48;
|
||||
public static float poweredSpawnerLevelThreePowerPerTick = 96;
|
||||
public static int poweredSpawnerMaxPlayerDistance = 0;
|
||||
public static boolean poweredSpawnerUseVanillaSpawChecks = false;
|
||||
public static double brokenSpawnerDropChance = 1;
|
||||
public static int powerSpawnerAddSpawnerCost = 30;
|
||||
|
||||
public static void load(FMLPreInitializationEvent event) {
|
||||
configDirectory = new File(event.getModConfigurationDirectory(), "enderio");
|
||||
@@ -475,7 +477,11 @@ public final class Config {
|
||||
"Max distance of the closest player for the spawner to be active. A zero value will remove the player check").getInt(poweredSpawnerMaxPlayerDistance);
|
||||
poweredSpawnerUseVanillaSpawChecks = config.get("PoweredSpawner Settings", "poweredSpawnerUseVanillaSpawChecks", poweredSpawnerUseVanillaSpawChecks,
|
||||
"If true, regular spawn checks such as lighting level and dimension will be made before spawning mobs").getBoolean(poweredSpawnerUseVanillaSpawChecks);
|
||||
|
||||
brokenSpawnerDropChance = (float)config.get("PoweredSpawner Settings", "brokenSpawnerDropChance", brokenSpawnerDropChance,
|
||||
"The chance a brokne spawner will be dropped when a spawner is broken. 1 = 100% chance, 0 = 0% chance").getDouble(brokenSpawnerDropChance);
|
||||
powerSpawnerAddSpawnerCost = config.get("PoweredSpawner Settings", "powerSpawnerAddSpawnerCost", powerSpawnerAddSpawnerCost,
|
||||
"The number of levels it costs to add a broken spawner").getInt(powerSpawnerAddSpawnerCost);
|
||||
|
||||
}
|
||||
|
||||
private Config() {
|
||||
|
||||
@@ -79,6 +79,7 @@ import crazypants.enderio.machine.power.BlockCapacitorBank;
|
||||
import crazypants.enderio.machine.reservoir.BlockReservoir;
|
||||
import crazypants.enderio.machine.solar.BlockSolarPanel;
|
||||
import crazypants.enderio.machine.spawner.BlockPoweredSpawner;
|
||||
import crazypants.enderio.machine.spawner.ItemBrokenSpawner;
|
||||
import crazypants.enderio.machine.still.BlockVat;
|
||||
import crazypants.enderio.machine.still.VatRecipeManager;
|
||||
import crazypants.enderio.machine.tank.BlockTank;
|
||||
@@ -168,6 +169,7 @@ public class EnderIO {
|
||||
public static BlockTank blockTank;
|
||||
public static BlockCrafter blockCrafter;
|
||||
public static BlockPoweredSpawner blockPoweredSpawner;
|
||||
public static ItemBrokenSpawner itemBrokenSpawner;
|
||||
|
||||
public static BlockElectricLight blockElectricLight;
|
||||
public static BlockLightNode blockLightNode;
|
||||
@@ -233,8 +235,7 @@ public class EnderIO {
|
||||
blockAlloySmelter = BlockAlloySmelter.create();
|
||||
blockVat = BlockVat.create();
|
||||
blockPowerMonitor = BlockPowerMonitor.create();
|
||||
blockFarmStation = BlockFarmStation.create();
|
||||
blockPoweredSpawner = BlockPoweredSpawner.create();
|
||||
blockFarmStation = BlockFarmStation.create();
|
||||
blockCapacitorBank = BlockCapacitorBank.create();
|
||||
|
||||
blockPainter = BlockPainter.create();
|
||||
@@ -264,6 +265,9 @@ public class EnderIO {
|
||||
blockConduitBundle = BlockConduitBundle.create();
|
||||
blockConduitFacade = BlockConduitFacade.create();
|
||||
itemConduitFacade = ItemConduitFacade.create();
|
||||
|
||||
blockPoweredSpawner = BlockPoweredSpawner.create();
|
||||
itemBrokenSpawner = ItemBrokenSpawner.create();
|
||||
|
||||
itemRedstoneConduit = ItemRedstoneConduit.create();
|
||||
itemPowerConduit = ItemPowerConduit.create();
|
||||
|
||||
@@ -47,7 +47,9 @@ public enum ModObject {
|
||||
blockFarmStation,
|
||||
blockTank,
|
||||
blockCrafter,
|
||||
|
||||
blockPoweredSpawner,
|
||||
itemBrokenSpawner,
|
||||
|
||||
blockElectricLight,
|
||||
blockLightNode,
|
||||
|
||||
@@ -71,13 +71,13 @@ public class TooltipAddera {
|
||||
}
|
||||
|
||||
Block blk = Block.getBlockFromItem(evt.itemStack.getItem());
|
||||
if(blk instanceof IResourceTooltipProvider) {
|
||||
addInformation((IResourceTooltipProvider)blk, evt);
|
||||
return;
|
||||
} else if(blk instanceof IAdvancedTooltipProvider) {
|
||||
if(blk instanceof IAdvancedTooltipProvider) {
|
||||
addInformation((IAdvancedTooltipProvider)blk, evt.itemStack, evt.entityPlayer, evt.toolTip, false);
|
||||
return;
|
||||
}
|
||||
} else if(blk instanceof IResourceTooltipProvider) {
|
||||
addInformation((IResourceTooltipProvider)blk, evt);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Config.addFuelTooltipsToAllFluidContainers) {
|
||||
addTooltipForFluid(evt.toolTip, evt.itemStack);
|
||||
|
||||
@@ -31,7 +31,8 @@ import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
|
||||
public abstract class AbstractMachineEntity extends TileEntityEio implements ISidedInventory, IInternalPowerReceptor, IMachine, IRedstoneModeControlable, IIoConfigurable {
|
||||
public abstract class AbstractMachineEntity extends TileEntityEio implements ISidedInventory, IInternalPowerReceptor, IMachine, IRedstoneModeControlable,
|
||||
IIoConfigurable {
|
||||
|
||||
public short facing;
|
||||
|
||||
@@ -73,7 +74,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
redstoneControlMode = RedstoneControlMode.IGNORE;
|
||||
|
||||
allSlots = new int[slotDefinition.getNumSlots()];
|
||||
for(int i=0;i<allSlots.length;i++) {
|
||||
for (int i = 0; i < allSlots.length; i++) {
|
||||
allSlots[i] = i;
|
||||
}
|
||||
}
|
||||
@@ -82,7 +83,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
public IoMode toggleIoModeForFace(ForgeDirection faceHit) {
|
||||
IoMode curMode = getIoMode(faceHit);
|
||||
IoMode mode = curMode.next();
|
||||
while(!supportsMode(faceHit, mode)) {
|
||||
while (!supportsMode(faceHit, mode)) {
|
||||
mode = mode.next();
|
||||
}
|
||||
setIoMode(faceHit, mode);
|
||||
@@ -275,7 +276,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
}
|
||||
|
||||
public int getMaxEnergyStoredMJ() {
|
||||
return (int)powerHandler.getMaxEnergyStored();
|
||||
return (int) powerHandler.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
// --- Process Loop
|
||||
@@ -306,7 +307,6 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
} // else is server, do all logic only on the server
|
||||
|
||||
updateStoredEnergyFromPowerHandler();
|
||||
@@ -318,7 +318,6 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
redstoneStateDirty = false;
|
||||
}
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
requiresClientSync |= doSideIo();
|
||||
}
|
||||
@@ -326,7 +325,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
requiresClientSync |= prevRedCheck != redstoneCheckPassed;
|
||||
|
||||
requiresClientSync |= processTasks(redstoneCheckPassed);
|
||||
|
||||
|
||||
boolean powerChanged = (lastSyncPowerStored != storedEnergy && worldObj.getTotalWorldTime() % 5 == 0);
|
||||
|
||||
if(requiresClientSync) {
|
||||
@@ -339,7 +338,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
markDirty();
|
||||
} else if(powerChanged) {
|
||||
lastSyncPowerStored = storedEnergy;
|
||||
PacketHandler.sendToAllAround(new PacketPowerStorage(this), this);
|
||||
PacketHandler.sendToAllAround(new PacketPowerStorage(this), this);
|
||||
}
|
||||
|
||||
if(notifyNeighbours) {
|
||||
@@ -353,10 +352,10 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
if(faceModes == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean res = false;
|
||||
Set<Entry<ForgeDirection, IoMode>> ents = faceModes.entrySet();
|
||||
for(Entry<ForgeDirection, IoMode> ent : ents) {
|
||||
for (Entry<ForgeDirection, IoMode> ent : ents) {
|
||||
IoMode mode = ent.getValue();
|
||||
if(mode.pulls()) {
|
||||
res = res | doPull(ent.getKey());
|
||||
@@ -381,8 +380,8 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
TileEntity te = worldObj.getTileEntity(loc.x, loc.y, loc.z);
|
||||
if(te == null) {
|
||||
return false;
|
||||
}
|
||||
for(int i=slotDefinition.minOutputSlot; i<= slotDefinition.maxOutputSlot;i++) {
|
||||
}
|
||||
for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
|
||||
ItemStack item = inventory[i];
|
||||
if(item != null) {
|
||||
int num = ItemUtil.doInsertItem(te, item, dir.getOpposite());
|
||||
@@ -392,7 +391,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
item = null;
|
||||
}
|
||||
inventory[i] = item;
|
||||
markDirty();
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -409,7 +408,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
}
|
||||
|
||||
boolean hasSpace = false;
|
||||
for(int slot=slotDefinition.minInputSlot; slot <= slotDefinition.maxInputSlot && !hasSpace;slot++) {
|
||||
for (int slot = slotDefinition.minInputSlot; slot <= slotDefinition.maxInputSlot && !hasSpace; slot++) {
|
||||
hasSpace = inventory[slot] == null ? true : inventory[slot].stackSize < inventory[slot].getMaxStackSize();
|
||||
}
|
||||
if(!hasSpace) {
|
||||
@@ -421,14 +420,14 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
if(te == null) {
|
||||
return false;
|
||||
}
|
||||
if( !(te instanceof IInventory)) {
|
||||
if(!(te instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
ISidedInventory target;
|
||||
if(te instanceof ISidedInventory) {
|
||||
target = (ISidedInventory)te;
|
||||
target = (ISidedInventory) te;
|
||||
} else {
|
||||
target = new InventoryWrapper((IInventory)te);
|
||||
target = new InventoryWrapper((IInventory) te);
|
||||
}
|
||||
|
||||
int[] targetSlots = target.getAccessibleSlotsFromSide(dir.getOpposite().ordinal());
|
||||
@@ -436,7 +435,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int inputSlot=slotDefinition.minInputSlot; inputSlot <= slotDefinition.maxInputSlot;inputSlot++) {
|
||||
for (int inputSlot = slotDefinition.minInputSlot; inputSlot <= slotDefinition.maxInputSlot; inputSlot++) {
|
||||
if(doPull(inputSlot, target, targetSlots, dir)) {
|
||||
return false;
|
||||
}
|
||||
@@ -446,7 +445,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
|
||||
protected boolean doPull(int inputSlot, ISidedInventory target, int[] targetSlots, ForgeDirection side) {
|
||||
ItemStack curStack = inventory[inputSlot];
|
||||
for(int i=0;i<targetSlots.length;i++) {
|
||||
for (int i = 0; i < targetSlots.length; i++) {
|
||||
int tSlot = targetSlots[i];
|
||||
ItemStack targetStack = target.getStackInSlot(tSlot);
|
||||
if(targetStack != null && target.canExtractItem(i, targetStack, side.getOpposite().ordinal())) {
|
||||
@@ -496,11 +495,13 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
inventory = new ItemStack[slotDefinition.getNumSlots()];
|
||||
|
||||
NBTTagList itemList = (NBTTagList) nbtRoot.getTag("Items");
|
||||
for (int i = 0; i < itemList.tagCount(); i++) {
|
||||
NBTTagCompound itemStack = itemList.getCompoundTagAt(i);
|
||||
byte slot = itemStack.getByte("Slot");
|
||||
if(slot >= 0 && slot < inventory.length) {
|
||||
inventory[slot] = ItemStack.loadItemStackFromNBT(itemStack);
|
||||
if(itemList != null) {
|
||||
for (int i = 0; i < itemList.tagCount(); i++) {
|
||||
NBTTagCompound itemStack = itemList.getCompoundTagAt(i);
|
||||
byte slot = itemStack.getByte("Slot");
|
||||
if(slot >= 0 && slot < inventory.length) {
|
||||
inventory[slot] = ItemStack.loadItemStackFromNBT(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +525,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
if(stack == null || stack.stackTagCompound == null) {
|
||||
return;
|
||||
}
|
||||
NBTTagCompound root = stack.stackTagCompound ;
|
||||
NBTTagCompound root = stack.stackTagCompound;
|
||||
if(!root.hasKey("eio.abstractMachine")) {
|
||||
return;
|
||||
}
|
||||
@@ -591,8 +592,6 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi
|
||||
stack.setStackDisplayName(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---- Inventory
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,31 +1,136 @@
|
||||
package crazypants.enderio.machine.spawner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import scala.tools.nsc.settings.AdvancedScalaSettings;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.block.BlockMobSpawner;
|
||||
import net.minecraft.block.BlockSponge;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.MobSpawnerBaseLogic;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityMobSpawner;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import crazypants.enderio.Config;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.AbstractMachineBlock;
|
||||
import crazypants.enderio.machine.MachineRecipeRegistry;
|
||||
import crazypants.enderio.machine.crusher.BlockCrusher;
|
||||
import crazypants.enderio.machine.crusher.PacketGrindingBall;
|
||||
import crazypants.enderio.machine.power.BlockItemCapacitorBank;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner> {
|
||||
public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner> implements IAdvancedTooltipProvider {
|
||||
|
||||
public static BlockPoweredSpawner create() {
|
||||
|
||||
// public static ItemStack createItemStackForSpawnerType(String type) {
|
||||
// ItemStack res = new ItemStack(EnderIO.blockPoweredSpawner);
|
||||
// res.stackTagCompound = new NBTTagCompound();
|
||||
// res.stackTagCompound.setString("mobType", type);
|
||||
// return res;
|
||||
// }
|
||||
|
||||
public static void writeMobTypeToNBT(NBTTagCompound nbt, String type) {
|
||||
if(nbt == null) {
|
||||
return;
|
||||
}
|
||||
if(type == null) {
|
||||
nbt.removeTag("mobType");
|
||||
} else {
|
||||
nbt.setString("mobType", type);
|
||||
}
|
||||
}
|
||||
|
||||
public static String readMobTypeFromNBT(NBTTagCompound nbt) {
|
||||
if(nbt == null) {
|
||||
return null;
|
||||
}
|
||||
if(!nbt.hasKey("mobType")) {
|
||||
return null;
|
||||
}
|
||||
return nbt.getString("mobType");
|
||||
}
|
||||
|
||||
public static String getSpawnerTypeFromItemStack(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() != Item.getItemFromBlock(EnderIO.blockPoweredSpawner)) {
|
||||
return null;
|
||||
}
|
||||
return readMobTypeFromNBT(stack.stackTagCompound);
|
||||
}
|
||||
|
||||
public static BlockPoweredSpawner create() {
|
||||
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPoweredSpawner.unlocalisedName, new DummyRecipe());
|
||||
|
||||
BlockPoweredSpawner res = new BlockPoweredSpawner();
|
||||
MinecraftForge.EVENT_BUS.register(res);
|
||||
res.init();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
protected BlockPoweredSpawner() {
|
||||
super(ModObject.blockPoweredSpawner, TilePoweredSpawner.class);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBreakEvent(BlockEvent.BreakEvent evt) {
|
||||
if(evt.block instanceof BlockMobSpawner) {
|
||||
if(evt.getPlayer() != null && !evt.getPlayer().capabilities.isCreativeMode) {
|
||||
TileEntity tile = evt.getPlayer().worldObj.getTileEntity(evt.x, evt.y, evt.z);
|
||||
if(tile instanceof TileEntityMobSpawner) {
|
||||
|
||||
if(Math.random() > Config.brokenSpawnerDropChance) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntityMobSpawner spawner = (TileEntityMobSpawner)tile;
|
||||
MobSpawnerBaseLogic logic = spawner.func_145881_a();
|
||||
if(logic != null) {
|
||||
String name = logic.getEntityNameToSpawn();
|
||||
if(name != null) {
|
||||
ItemStack drop = ItemBrokenSpawner.createStackForMobType(name);
|
||||
Util.dropItems(evt.getPlayer().worldObj, drop, evt.x, evt.y, evt.z, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleAnvilEvent(AnvilUpdateEvent evt) {
|
||||
if(evt.left == null || evt.left.getItem() != Item.getItemFromBlock(EnderIO.blockPoweredSpawner) ||
|
||||
evt.right == null || ItemBrokenSpawner.getMobTypeFromStack(evt.right) == null) {
|
||||
return;
|
||||
}
|
||||
evt.cost = Config.powerSpawnerAddSpawnerCost;
|
||||
evt.output = evt.left.copy();
|
||||
if(evt.output.stackTagCompound == null) {
|
||||
evt.output.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
evt.output.stackTagCompound.setBoolean("eio.abstractMachine", true);
|
||||
writeMobTypeToNBT(evt.output.stackTagCompound, ItemBrokenSpawner.getMobTypeFromStack(evt.right));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
@@ -54,4 +159,30 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
String type = getSpawnerTypeFromItemStack(itemstack);
|
||||
if(type != null) {
|
||||
list.add(type);
|
||||
} else {
|
||||
list.add(Lang.localize("tile.blockPoweredSpawner.tooltip.empty", false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
String type = getSpawnerTypeFromItemStack(itemstack);
|
||||
if(type == null) {
|
||||
TooltipAddera.addDetailedTooltipFromResources(list, "tile.blockPoweredSpawner.empty");
|
||||
} else {
|
||||
TooltipAddera.addDetailedTooltipFromResources(list, "tile.blockPoweredSpawner");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package crazypants.enderio.machine.spawner;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.render.IconUtil;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
public class BrokenSpawnerRenderer implements IItemRenderer {
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
RenderBlocks rb = (RenderBlocks)data[0];
|
||||
rb.setOverrideBlockTexture(EnderIO.itemBrokenSpawner.getIconFromDamage(0));
|
||||
rb.renderBlockAsItem(Blocks.stone, 0, 1);
|
||||
rb.setOverrideBlockTexture(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package crazypants.enderio.machine.spawner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.material.ItemCapacitor;
|
||||
import crazypants.enderio.power.Capacitors;
|
||||
import crazypants.enderio.power.ICapacitor;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class ItemBrokenSpawner extends Item {
|
||||
|
||||
private static final String[] CREATIVE_TYPES = new String[] {
|
||||
"Skeleton",
|
||||
"Zombie",
|
||||
"Spider",
|
||||
"CaveSpider",
|
||||
"Blaze"
|
||||
};
|
||||
|
||||
public static String getMobTypeFromStack(ItemStack stack) {
|
||||
if(stack == null || stack.stackTagCompound == null || !stack.stackTagCompound.hasKey("mobType")) {
|
||||
return null;
|
||||
}
|
||||
return stack.stackTagCompound.getString("mobType");
|
||||
}
|
||||
|
||||
public static ItemStack createStackForMobType(String mobType) {
|
||||
if(mobType == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack res = new ItemStack(EnderIO.itemBrokenSpawner);
|
||||
res.stackTagCompound = new NBTTagCompound();
|
||||
res.stackTagCompound.setString("mobType", mobType);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static ItemBrokenSpawner create() {
|
||||
ItemBrokenSpawner result = new ItemBrokenSpawner();
|
||||
result.init();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected ItemBrokenSpawner() {
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
setUnlocalizedName(ModObject.itemBrokenSpawner.unlocalisedName);
|
||||
setHasSubtypes(true);
|
||||
setMaxDamage(0);
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void init() {
|
||||
GameRegistry.registerItem(this, ModObject.itemBrokenSpawner.unlocalisedName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iIconRegister) {
|
||||
itemIcon = iIconRegister.registerIcon("enderio:itemBrokenSpawner");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
|
||||
for(String mobType : CREATIVE_TYPES) {
|
||||
par3List.add(createStackForMobType(mobType));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||
if(par1ItemStack != null && par1ItemStack.stackTagCompound != null) {
|
||||
String mobName = getMobTypeFromStack(par1ItemStack);
|
||||
if(mobName != null) {
|
||||
par3List.add(mobName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,11 +35,14 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
|
||||
public static final boolean USE_VANILLA_SPAWN_CHECKS = Config.poweredSpawnerUseVanillaSpawChecks;
|
||||
|
||||
private final MobSpawnerBaseLogic logic = new SpawnerLogic();
|
||||
|
||||
private static final String NULL_ENTITY_NAME = "None";
|
||||
|
||||
public TilePoweredSpawner() {
|
||||
super(new SlotDefinition(0, 0));
|
||||
//logic.setEntityName("Zombie");
|
||||
logic.setEntityName("Skeleton");
|
||||
//logic.setEntityName("Skeleton");
|
||||
logic.setEntityName(NULL_ENTITY_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,6 +63,9 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
|
||||
|
||||
@Override
|
||||
protected IMachineRecipe canStartNextTask(float chance) {
|
||||
if(logic.getEntityNameToSpawn() == null || logic.getEntityNameToSpawn().equals(NULL_ENTITY_NAME)) {
|
||||
return null;
|
||||
}
|
||||
return new DummyRecipe();
|
||||
}
|
||||
|
||||
@@ -89,13 +95,35 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
|
||||
public void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
super.readCustomNBT(nbtRoot);
|
||||
logic.readFromNBT(nbtRoot);
|
||||
super.readCustomNBT(nbtRoot);
|
||||
logic.readFromNBT(nbtRoot);
|
||||
}
|
||||
|
||||
public void writeCustomNBT(NBTTagCompound nbtRoot) {
|
||||
super.writeCustomNBT(nbtRoot);
|
||||
logic.writeToNBT(nbtRoot);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
String mobType = BlockPoweredSpawner.readMobTypeFromNBT(nbtRoot);
|
||||
if(mobType == null) {
|
||||
mobType = NULL_ENTITY_NAME;
|
||||
}
|
||||
logic.setEntityName(mobType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
String mobType = logic.getEntityNameToSpawn();
|
||||
if(mobType == null || mobType.equals(NULL_ENTITY_NAME)) {
|
||||
BlockPoweredSpawner.writeMobTypeToNBT(nbtRoot, null);
|
||||
} else {
|
||||
BlockPoweredSpawner.writeMobTypeToNBT(nbtRoot, mobType);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateEntity() {
|
||||
|
||||
Reference in new issue
Block a user