From d45a1a8c4aee8d45c5f2557662f74453ffe744f0 Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 16 Jun 2025 17:58:55 +0200 Subject: [PATCH] change mob spawners --- .../java/client/gui/container/GuiTile.java | 2 +- .../client/network/ClientLoginHandler.java | 4 +- .../TileEntityMobSpawnerRenderer.java | 38 --- .../TileEntityRendererDispatcher.java | 2 - .../main/java/client/world/WorldClient.java | 12 - .../common/block/tech/BlockMobSpawner.java | 89 +------ .../common/block/tech/BlockTianReactor.java | 2 +- .../main/java/common/init/BlockRegistry.java | 2 +- .../main/java/common/init/TileRegistry.java | 2 +- .../java/common/inventory/ContainerTile.java | 14 +- .../java/common/item/ItemMonsterPlacer.java | 66 +---- .../main/java/common/item/ItemNpcSpawner.java | 27 +- .../common/tileentity/TileEntityDevice.java | 27 +- .../tileentity/TileEntityMobSpawner.java | 249 ++++-------------- .../tileentity/TileEntityTianReactor.java | 3 +- server/src/main/java/server/vars/SVars.java | 10 +- .../src/main/java/server/world/Converter.java | 4 +- .../java/server/worldgen/FeatureDungeons.java | 43 +-- .../worldgen/structure/StructureBridge.java | 17 +- .../structure/StructureMineshaft.java | 17 +- .../structure/StructureStronghold.java | 17 +- .../worldgen/structure/StructureVillage.java | 2 +- 22 files changed, 190 insertions(+), 459 deletions(-) delete mode 100755 client/src/main/java/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java diff --git a/client/src/main/java/client/gui/container/GuiTile.java b/client/src/main/java/client/gui/container/GuiTile.java index c5a0591..018826d 100755 --- a/client/src/main/java/client/gui/container/GuiTile.java +++ b/client/src/main/java/client/gui/container/GuiTile.java @@ -27,6 +27,6 @@ public class GuiTile extends GuiContainer this.drawString(this.tile.getStatus().color + this.tileInv.getCommandName() + " - " + this.tile.getStatus().name, 8, 6); this.drawString(this.playerInv.getCommandName(), 8, this.ySize - 96 + 2); this.drawString(String.format("Temperatur: %d °", this.tile.getTemperature()), 8, 18); - this.drawString(this.tile.formatDisplay(), 8, 28); + this.drawString(this.tile.formatDisplay((ContainerTile)this.inventorySlots), 8, 28); } } diff --git a/client/src/main/java/client/network/ClientLoginHandler.java b/client/src/main/java/client/network/ClientLoginHandler.java index 0509522..2721d05 100755 --- a/client/src/main/java/client/network/ClientLoginHandler.java +++ b/client/src/main/java/client/network/ClientLoginHandler.java @@ -168,8 +168,8 @@ public class ClientLoginHandler implements IClientLoginHandler { this.connection.closeChannel("Der Server unterstützt keine der vorhandenen\nAuthentifizierungsmethoden\n\nUnterstützt vom Server: " + (!passwordAuth && !pubkeyAuth ? "Keine" : ((passwordAuth ? "Passwort" : "") + (passwordAuth && pubkeyAuth ? " und " : "") + (pubkeyAuth ? "Pubkey" : ""))) + "\n\nVorhanden in Konfiguration für '" + this.server.getName() + "': " + (this.server.getPassword().isEmpty() && this.server.getKeypair() == null ? "Keine" : - ((this.server.getPassword().isEmpty() ? "Passwort" : "") + - (this.server.getPassword().isEmpty() && this.server.getKeypair() != null ? " und " : "") + (this.server.getKeypair() != null ? "Pubkey" : "")))); + ((!this.server.getPassword().isEmpty() ? "Passwort" : "") + + (!this.server.getPassword().isEmpty() && this.server.getKeypair() != null ? " und " : "") + (this.server.getKeypair() != null ? "Pubkey" : "")))); return; } if(auth && pubkeyAuth && this.server.getKeypair() != null) { diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java b/client/src/main/java/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java deleted file mode 100755 index ae555c7..0000000 --- a/client/src/main/java/client/renderer/tileentity/TileEntityMobSpawnerRenderer.java +++ /dev/null @@ -1,38 +0,0 @@ -package client.renderer.tileentity; - -import org.lwjgl.opengl.GL11; - -import client.Client; -import common.entity.Entity; -import common.tileentity.TileEntityMobSpawner; - -public class TileEntityMobSpawnerRenderer extends TileEntitySpecialRenderer -{ - public void renderTileEntityAt(TileEntityMobSpawner te, double x, double y, double z, float partialTicks, int destroyStage) - { - GL11.glPushMatrix(); - GL11.glTranslatef((float)x + 0.5F, (float)y, (float)z + 0.5F); - renderMob(te, x, y, z, partialTicks); - GL11.glPopMatrix(); - } - - /** - * Render the mob inside the mob spawner. - */ - public static void renderMob(TileEntityMobSpawner mobSpawnerLogic, double posX, double posY, double posZ, float partialTicks) - { - Entity entity = mobSpawnerLogic.createRenderEntity(mobSpawnerLogic.getWorld()); - - if (entity != null) - { - float f = 0.4375F; - GL11.glTranslatef(0.0F, 0.4F, 0.0F); - GL11.glRotatef((float)(mobSpawnerLogic.getPrevMobRotation() + (mobSpawnerLogic.getMobRotation() - mobSpawnerLogic.getPrevMobRotation()) * (double)partialTicks) * 10.0F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-30.0F, 1.0F, 0.0F, 0.0F); - GL11.glTranslatef(0.0F, -0.4F, 0.0F); - GL11.glScalef(f, f, f); - entity.setLocationAndAngles(posX, posY, posZ, 0.0F, 0.0F); - Client.CLIENT.getRenderManager().renderEntity(entity, 0.0D, 0.0D, 0.0D, partialTicks); - } - } -} diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java b/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java index 149cb2b..88572fc 100755 --- a/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java +++ b/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java @@ -11,7 +11,6 @@ import common.entity.Entity; import common.tileentity.TileEntity; import common.tileentity.TileEntityBanner; import common.tileentity.TileEntityChest; -import common.tileentity.TileEntityMobSpawner; import common.tileentity.TileEntityPiston; import common.tileentity.TileEntitySign; import common.util.BlockPos; @@ -47,7 +46,6 @@ public class TileEntityRendererDispatcher private TileEntityRendererDispatcher() { this.mapSpecialRenderers.put(TileEntitySign.class, new TileEntitySignRenderer()); - this.mapSpecialRenderers.put(TileEntityMobSpawner.class, new TileEntityMobSpawnerRenderer()); this.mapSpecialRenderers.put(TileEntityPiston.class, new TileEntityPistonRenderer()); this.mapSpecialRenderers.put(TileEntityChest.class, new TileEntityChestRenderer()); this.mapSpecialRenderers.put(TileEntityBanner.class, new TileEntityBannerRenderer()); diff --git a/client/src/main/java/client/world/WorldClient.java b/client/src/main/java/client/world/WorldClient.java index 00a3a76..dbfdf90 100755 --- a/client/src/main/java/client/world/WorldClient.java +++ b/client/src/main/java/client/world/WorldClient.java @@ -695,18 +695,6 @@ public class WorldClient extends AWorldClient this.playSoundAtPos(blockPosIn, SoundEvent.GLASS, 1.0F); break; - case 2004: - for (int k = 0; k < 20; ++k) - { - double d3 = (double)blockPosIn.getX() + 0.5D + ((double)this.rand.floatv() - 0.5D) * 2.0D; - double d5 = (double)blockPosIn.getY() + 0.5D + ((double)this.rand.floatv() - 0.5D) * 2.0D; - double d7 = (double)blockPosIn.getZ() + 0.5D + ((double)this.rand.floatv() - 0.5D) * 2.0D; - this.spawnParticle(ParticleType.SMOKE_NORMAL, d3, d5, d7, 0.0D, 0.0D, 0.0D); - this.spawnParticle(ParticleType.FLAME, d3, d5, d7, 0.0D, 0.0D, 0.0D); - } - - return; - case 2005: ItemDye.spawnBonemealParticles(this, blockPosIn, data); } diff --git a/common/src/main/java/common/block/tech/BlockMobSpawner.java b/common/src/main/java/common/block/tech/BlockMobSpawner.java index 4a46f35..789d1cc 100755 --- a/common/src/main/java/common/block/tech/BlockMobSpawner.java +++ b/common/src/main/java/common/block/tech/BlockMobSpawner.java @@ -1,91 +1,16 @@ package common.block.tech; -import common.block.BlockContainer; -import common.block.Material; -import common.item.CheatTab; -import common.item.Item; import common.model.BlockLayer; -import common.rng.Random; import common.tileentity.TileEntity; import common.tileentity.TileEntityMobSpawner; -import common.util.BlockPos; -import common.world.State; import common.world.World; -public class BlockMobSpawner extends BlockContainer -{ - public BlockMobSpawner() - { - super(Material.SOLID); - this.setTab(CheatTab.TECHNOLOGY); - } +public class BlockMobSpawner extends BlockMachine { + public TileEntity createNewTileEntity(World world) { + return new TileEntityMobSpawner(); + } - /** - * Returns a new instance of a block's tile entity class. Called on placing the block. - */ - public TileEntity createNewTileEntity(World worldIn) - { - return new TileEntityMobSpawner(); - } - - /** - * Get the Item that this Block should drop when harvested. - */ - public Item getItemDropped(State state, Random rand, int fortune) - { - return null; - } - - /** - * Returns the quantity of items to drop on block destruction. - */ - public int quantityDropped(Random random) - { - return 0; - } - - /** - * Spawns this Block's drops into the World as EntityItems. - */ - public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, State state, float chance, int fortune) - { - super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune); - int i = worldIn.rand.rangeBonus(15, 29, 14); - this.dropXpOnBlockBreak(worldIn, pos, i); - } - - /** - * Used to determine ambient occlusion and culling when rebuilding chunks for render - */ - public boolean isOpaqueCube() - { - return false; - } - - /** - * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render - */ - public int getRenderType() - { - return 3; - } - - public BlockLayer getBlockLayer() - { - return BlockLayer.CUTOUT; - } - - public Item getItem(World worldIn, BlockPos pos) - { - return null; - } - - public boolean isXrayVisible() - { - return true; - } - - public boolean isMagnetic() { - return true; - } + public BlockLayer getBlockLayer() { + return BlockLayer.CUTOUT; + } } diff --git a/common/src/main/java/common/block/tech/BlockTianReactor.java b/common/src/main/java/common/block/tech/BlockTianReactor.java index 0ba0921..9d3ae88 100755 --- a/common/src/main/java/common/block/tech/BlockTianReactor.java +++ b/common/src/main/java/common/block/tech/BlockTianReactor.java @@ -11,7 +11,7 @@ import common.world.State; import common.world.World; public class BlockTianReactor extends BlockMachine { - public TileEntity createNewTileEntity(World worldIn) { + public TileEntity createNewTileEntity(World world) { return new TileEntityTianReactor(); } diff --git a/common/src/main/java/common/init/BlockRegistry.java b/common/src/main/java/common/init/BlockRegistry.java index 67196f2..abb3594 100755 --- a/common/src/main/java/common/init/BlockRegistry.java +++ b/common/src/main/java/common/init/BlockRegistry.java @@ -610,7 +610,7 @@ public abstract class BlockRegistry { registerBlock(2000, "core", new BlockCore().setHardness(1.5F).setResistance(10.0F).setStepSound(SoundType.STONE) .setDisplay("Chunk-Lade-Kern")); registerBlock(2001, "mob_spawner", - (new BlockMobSpawner()).setHardness(5.0F).setStepSound(SoundType.STONE).setDisplay("Monsterspawner")); + (new BlockMobSpawner()).setHardness(3.0F).setResistance(8.0F).setStepSound(SoundType.STONE).setDisplay("Mob-Spawner")); registerBlock(2002, "workbench", (new BlockWorkbench(3)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Werkbank")); registerBlock(2003, "furnace", (new BlockFurnace(false)).setHardness(3.5F).setStepSound(SoundType.STONE).setDisplay("Ofen") .setTab(CheatTab.TECHNOLOGY)); diff --git a/common/src/main/java/common/init/TileRegistry.java b/common/src/main/java/common/init/TileRegistry.java index 0435bd3..4ebcac4 100755 --- a/common/src/main/java/common/init/TileRegistry.java +++ b/common/src/main/java/common/init/TileRegistry.java @@ -41,7 +41,6 @@ public abstract class TileRegistry { addMapping(TileEntityDispenser.class, "Trap"); addMapping(TileEntityDropper.class, "Dropper"); addMapping(TileEntitySign.class, "Sign"); - addMapping(TileEntityMobSpawner.class, "MobSpawner"); addMapping(TileEntityPiston.class, "Piston"); addMapping(TileEntityBrewingStand.class, "Cauldron"); addMapping(TileEntityEnchantmentTable.class, "EnchantTable"); @@ -51,5 +50,6 @@ public abstract class TileRegistry { addMapping(TileEntityComparator.class, "Comparator"); addMapping(TileEntityBanner.class, "Banner"); addMapping(TileEntityTianReactor.class, "TianReactor"); + addMapping(TileEntityMobSpawner.class, "MobSpawner"); } } diff --git a/common/src/main/java/common/inventory/ContainerTile.java b/common/src/main/java/common/inventory/ContainerTile.java index ff7169a..e697fff 100755 --- a/common/src/main/java/common/inventory/ContainerTile.java +++ b/common/src/main/java/common/inventory/ContainerTile.java @@ -99,7 +99,11 @@ public class ContainerTile extends Container public void onCraftGuiOpened(ICrafting listener) { super.onCraftGuiOpened(listener); -// listener.sendAllWindowProperties(this, this.machine); + listener.sendProgressBarUpdate(this, this.resources.length, this.tile.getTemperature()); + listener.sendProgressBarUpdate(this, this.resources.length + 1, this.tile.getStatus().ordinal()); + for(int z = 0; z < this.resources.length; z++) { + listener.sendProgressBarUpdate(this, z, this.tile.getResource(z).getValue()); + } } public void updateProgressBar(int id, int data) @@ -118,14 +122,14 @@ public class ContainerTile extends Container for (int i = 0; i < this.crafters.size(); ++i) { - ICrafting icrafting = (ICrafting)this.crafters.get(i); + ICrafting listener = this.crafters.get(i); if(this.temperature != this.tile.getTemperature()) - icrafting.sendProgressBarUpdate(this, this.resources.length, this.tile.getTemperature()); + listener.sendProgressBarUpdate(this, this.resources.length, this.tile.getTemperature()); if(this.status != this.tile.getStatus()) - icrafting.sendProgressBarUpdate(this, this.resources.length + 1, this.tile.getStatus().ordinal()); + listener.sendProgressBarUpdate(this, this.resources.length + 1, this.tile.getStatus().ordinal()); for(int z = 0; z < this.resources.length; z++) { if(this.resources[z] != this.tile.getResource(z).getValue()) - icrafting.sendProgressBarUpdate(this, z, this.tile.getResource(z).getValue()); + listener.sendProgressBarUpdate(this, z, this.tile.getResource(z).getValue()); } } diff --git a/common/src/main/java/common/item/ItemMonsterPlacer.java b/common/src/main/java/common/item/ItemMonsterPlacer.java index 9747a18..1cb45c3 100755 --- a/common/src/main/java/common/item/ItemMonsterPlacer.java +++ b/common/src/main/java/common/item/ItemMonsterPlacer.java @@ -9,14 +9,11 @@ import common.dimension.Dimension; import common.entity.Entity; import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; -import common.init.Blocks; import common.init.EntityInfo; import common.init.EntityRegistry; import common.init.UniverseRegistry; import common.model.Model; import common.model.ModelProvider; -import common.tileentity.TileEntity; -import common.tileentity.TileEntityMobSpawner; import common.util.BlockPos; import common.util.ExtMath; import common.util.Facing; @@ -83,26 +80,6 @@ public class ItemMonsterPlacer extends Item { State iblockstate = worldIn.getState(pos); - if (iblockstate.getBlock() == Blocks.mob_spawner) - { - TileEntity tileentity = worldIn.getTileEntity(pos); - - if (tileentity instanceof TileEntityMobSpawner) - { -// MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic(); - ((TileEntityMobSpawner)tileentity).setEntityName(this.entityId); - tileentity.markDirty(); - worldIn.markBlockForUpdate(pos); - -// if (!playerIn.creative) -// { - --stack.size; -// } - - return true; - } - } - pos = pos.offset(side); double d0 = 0.0D; @@ -207,38 +184,21 @@ public class ItemMonsterPlacer extends Item } } - /** - * Spawns the creature specified by the egg's type in the location specified by the last three parameters. - * Parameters: world, entityID, x, y, z. - */ - public static Entity spawnCreature(World worldIn, String entityID, double x, double y, double z) - { + public static EntityLiving spawnCreature(World worldIn, String entityID, double x, double y, double z) { if (!EntityRegistry.SPAWN_EGGS.containsKey(entityID)) - { return null; - } - else - { - Entity entity = null; - - for (int i = 0; i < 1; ++i) - { - entity = EntityRegistry.createEntityByName(entityID, worldIn); - - if (entity instanceof EntityLiving) - { - EntityLiving entityliving = (EntityLiving)entity; - entity.setLocationAndAngles(x, y, z, ExtMath.wrapf(worldIn.rand.floatv() * 360.0F), 0.0F); - entityliving.headYaw = entityliving.rotYaw; - entityliving.yawOffset = entityliving.rotYaw; - entityliving.onInitialSpawn(null); - worldIn.spawnEntityInWorld(entity); - entityliving.playLivingSound(); - } - } - - return entity; - } + Entity entity = EntityRegistry.createEntityByName(entityID, worldIn); + if(!(entity instanceof EntityLiving living)) + return null; + living.setLocationAndAngles(x, y, z, ExtMath.wrapf(worldIn.rand.floatv() * 360.0F), 0.0F); + if(!living.isNotColliding()) + return null; + living.headYaw = living.rotYaw; + living.yawOffset = living.rotYaw; + living.onInitialSpawn(null); + worldIn.spawnEntityInWorld(living); + living.playLivingSound(); + return living; } // /** diff --git a/common/src/main/java/common/item/ItemNpcSpawner.java b/common/src/main/java/common/item/ItemNpcSpawner.java index a586fa8..9318d1d 100755 --- a/common/src/main/java/common/item/ItemNpcSpawner.java +++ b/common/src/main/java/common/item/ItemNpcSpawner.java @@ -33,16 +33,25 @@ public class ItemNpcSpawner extends Item this.setTab(CheatTab.SPAWNERS); this.spawned = spawned; } - - public String getDisplay(ItemStack stack) - { - String item = "Erschaffe"; - CharacterInfo info = this.spawned; // SpeciesRegistry.CHARACTERS.get(stack.getMetadata() % SpeciesRegistry.CHARACTERS.size()); + + public CharacterInfo getSpawnedChar() { + return this.spawned; + } + + public String getCharName() { + CharacterInfo info = this.spawned; // SpeciesRegistry.CHARACTERS.get(stack.getMetadata() % SpeciesRegistry.CHARACTERS.size()); String species = EntityRegistry.getEntityName(info.species.id); if(info.species.prefix && info.type != null && !info.type.toString().isEmpty()) species = info.type.toString(); String character = info.name; - item = item + " " + species + (character.isEmpty() ? "" : (" " + character)); + return species + (character.isEmpty() ? "" : (" " + character)); + } + + public String getDisplay(ItemStack stack) + { + String item = "Erschaffe"; + + item = item + " " + this.getCharName(); return item; } @@ -161,9 +170,8 @@ public class ItemNpcSpawner extends Item } } - public static Entity spawnNpc(World worldIn, CharacterInfo character, double x, double y, double z) + public static EntityNPC spawnNpc(World worldIn, CharacterInfo character, double x, double y, double z) { -// CharacterInfo character = SpeciesRegistry.CHARACTERS.get(entityID % SpeciesRegistry.CHARACTERS.size()); EntityNPC entity; try { entity = character.species.clazz.getConstructor(World.class).newInstance(worldIn); @@ -172,10 +180,11 @@ public class ItemNpcSpawner extends Item throw new RuntimeException(e); } entity.setLocationAndAngles(x, y, z, ExtMath.wrapf(worldIn.rand.floatv() * 360.0F), 0.0F); + if(!entity.isNotColliding()) + return null; entity.headYaw = entity.rotYaw; entity.yawOffset = entity.rotYaw; entity.onInitialSpawn(new CharacterTypeData(character)); -// entity.setFromInfo(character); worldIn.spawnEntityInWorld(entity); return entity; } diff --git a/common/src/main/java/common/tileentity/TileEntityDevice.java b/common/src/main/java/common/tileentity/TileEntityDevice.java index 3b48d6b..40d1c1a 100755 --- a/common/src/main/java/common/tileentity/TileEntityDevice.java +++ b/common/src/main/java/common/tileentity/TileEntityDevice.java @@ -42,9 +42,18 @@ public abstract class TileEntityDevice extends TileEntityLockable implements IHo this.resources = resources; } - protected abstract int getTempIncrement(); - protected abstract int getTempDecrement(); - protected abstract int getMaxTemp(); + protected int getTempIncrement() { + return -1; + } + + protected int getTempDecrement() { + return -1; + } + + protected int getMaxTemp() { + return Integer.MAX_VALUE; + } + protected abstract boolean executeFunction(); public MachineResource getResource(int slot) { @@ -203,7 +212,10 @@ public abstract class TileEntityDevice extends TileEntityLockable implements IHo if(this.worldObj != null && !this.worldObj.client && this.status != Status.BROKEN) { int envTemp = (int)this.worldObj.getTemperatureC(this.getPos()); if(this.executeFunction()) { - this.temperature += this.getTempIncrement(); + if(this.getTempIncrement() < 0) + this.temperature = envTemp; + else + this.temperature += this.getTempIncrement(); this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : Status.RUNNING; if(this.temperature > this.getMaxTemp()) { this.status = Status.BROKEN; @@ -219,7 +231,10 @@ public abstract class TileEntityDevice extends TileEntityLockable implements IHo int dec = this.getTempDecrement(); if(dec != 0) { int prev = this.temperature; - this.temperature -= dec; + if(dec < 0) + this.temperature = envTemp; + else + this.temperature -= dec; this.temperature = ExtMath.clampi(this.temperature, envTemp, Integer.MAX_VALUE); if(prev != this.temperature) this.markDirty(); @@ -318,5 +333,5 @@ public abstract class TileEntityDevice extends TileEntityLockable implements IHo return 0x8080ff; } - public abstract String formatDisplay(); + public abstract String formatDisplay(ContainerTile inv); } diff --git a/common/src/main/java/common/tileentity/TileEntityMobSpawner.java b/common/src/main/java/common/tileentity/TileEntityMobSpawner.java index 1b7591a..2092028 100755 --- a/common/src/main/java/common/tileentity/TileEntityMobSpawner.java +++ b/common/src/main/java/common/tileentity/TileEntityMobSpawner.java @@ -1,150 +1,70 @@ package common.tileentity; -import common.entity.Entity; import common.entity.types.EntityLiving; -import common.init.Blocks; import common.init.EntityRegistry; -import common.model.ParticleType; -import common.network.Packet; -import common.packet.SPacketUpdateTileEntity; +import common.inventory.ContainerTile; +import common.item.ItemMonsterPlacer; +import common.item.ItemNpcSpawner; +import common.item.ItemStack; import common.tags.TagObject; -import common.util.BlockPos; -import common.util.BoundingBox; import common.vars.Vars; -import common.world.World; -public class TileEntityMobSpawner extends TileEntity implements ITickable +public class TileEntityMobSpawner extends TileEntityDevice implements ITickable { - private int spawnDelay = 20; - private String mobID = "Pig"; - private double mobRotation; - private double prevMobRotation; + public TileEntityMobSpawner() { + super(1); + } + + private int spawnDelay = 20; private int minSpawnDelay = 200; private int maxSpawnDelay = 800; - private int spawnCount = 4; - private Entity cachedEntity; - private int maxNearbyEntities = 6; - private int activatingRangeFromPlayer = 16; private int spawnRange = 4; - - public Packet getDescriptionPacket() - { - return new SPacketUpdateTileEntity(this); - } - public boolean receiveClientEvent(int id, int type) - { - if (id == 1 && this.worldObj.client) - { - this.spawnDelay = this.minSpawnDelay; + public boolean isItemValidForSlot(int index, ItemStack stack) { + return index == 0 ? stack.getItem() instanceof ItemMonsterPlacer || stack.getItem() instanceof ItemNpcSpawner : false; + } + + public String getName() { + return "Mob-Spawner"; + } + + public String getGuiID() { + return "mob_spawner"; + } + + public String formatDisplay(ContainerTile inv) { + ItemStack stack = inv.getSlot(0).getStack(); + if(stack == null) + return "Kein Spawner vorhanden"; + return String.format("Erschaffe: %s", stack.getItem() instanceof ItemMonsterPlacer egg ? EntityRegistry.getEntityName(egg.getSpawnedId()) : ((stack.getItem() instanceof ItemNpcSpawner egg ? egg.getCharName() : ""))); + } + + protected boolean executeFunction() { + if(!Vars.mobs || !Vars.spawners || !this.hasAmount(0, 1)) + return false; + if (this.spawnDelay == -1) + this.resetTimer(); + if (this.spawnDelay > 0) { + --this.spawnDelay; return true; } - else - { - return super.receiveClientEvent(id, type); - } - } - -// public boolean hasSpecialNBT() -// { -// return true; -// } - - public int getColor() { - return 0xff0000; - } - - public void update() - { - BlockPos blockpos = this.pos; - if (this.worldObj.isAnyPlayerWithinRangeAt((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D, (double)this.activatingRangeFromPlayer)) - { - if (this.worldObj.client) - { - double d3 = (double)((float)blockpos.getX() + this.worldObj.rand.floatv()); - double d4 = (double)((float)blockpos.getY() + this.worldObj.rand.floatv()); - double d5 = (double)((float)blockpos.getZ() + this.worldObj.rand.floatv()); - this.worldObj.spawnParticle(ParticleType.SMOKE_NORMAL, d3, d4, d5, 0.0D, 0.0D, 0.0D); - this.worldObj.spawnParticle(ParticleType.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D); - - if (this.spawnDelay > 0) - { - --this.spawnDelay; - } - - this.prevMobRotation = this.mobRotation; - this.mobRotation = (this.mobRotation + (double)(1000.0F / ((float)this.spawnDelay + 200.0F))) % 360.0D; - } - else - { - if(!Vars.mobs || !Vars.spawners) { - return; - } - - if (this.spawnDelay == -1) - { - this.resetTimer(); - } - - if (this.spawnDelay > 0) - { - --this.spawnDelay; - return; - } - - boolean flag = false; - - for (int i = 0; i < this.spawnCount; ++i) - { - Entity entity = EntityRegistry.createEntityByName(this.mobID, this.worldObj); - - if (entity == null) - { - return; - } - - int j = this.worldObj.getEntitiesWithinAABB(entity.getClass(), (new BoundingBox((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ(), (double)(blockpos.getX() + 1), (double)(blockpos.getY() + 1), (double)(blockpos.getZ() + 1))).expand((double)this.spawnRange, (double)this.spawnRange, (double)this.spawnRange)).size(); - - if (j >= this.maxNearbyEntities) - { - this.resetTimer(); - return; - } - - double d0 = (double)blockpos.getX() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; - double d1 = (double)(blockpos.getY() + this.worldObj.rand.zrange(3) - 1); - double d2 = (double)blockpos.getZ() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; - EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null; - entity.setLocationAndAngles(d0, d1, d2, this.worldObj.rand.floatv() * 360.0F, 0.0F); - - if (entityliving == null || entityliving.getCanSpawnHere() && entityliving.isNotColliding()) - { - if (entity instanceof EntityLiving && entity.worldObj != null) - { -// if (entity instanceof EntityLiving) -// { - ((EntityLiving)entity).onInitialSpawn(null); -// } - - entity.worldObj.spawnEntityInWorld(entity); - } - this.worldObj.playAuxSFX(2004, blockpos, 0); - - if (entityliving != null) - { - entityliving.spawnExplosionParticle(); - } - - flag = true; - } - } - - if (flag) - { - this.resetTimer(); - } - } - } + ItemStack stack = this.getStackInSlot(0); + if(stack == null) + return true; + double x = (double)this.pos.getX() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; + double y = (double)(this.pos.getY() + this.worldObj.rand.zrange(3) - 1); + double z = (double)this.pos.getZ() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; + EntityLiving entity = null; + if(stack.getItem() instanceof ItemMonsterPlacer egg) + entity = ItemMonsterPlacer.spawnCreature(this.worldObj, egg.getSpawnedId(), x, y, z); + else if(stack.getItem() instanceof ItemNpcSpawner egg) + entity = ItemNpcSpawner.spawnNpc(this.worldObj, egg.getSpawnedChar(), x, y, z); + if (entity == null) + return true; + this.decrStackSize(0, 1); + entity.spawnExplosionParticle(); + this.resetTimer(); + return true; } private void resetTimer() @@ -158,86 +78,31 @@ public class TileEntityMobSpawner extends TileEntity implements ITickable int i = this.maxSpawnDelay - this.minSpawnDelay; this.spawnDelay = this.minSpawnDelay + this.worldObj.rand.zrange(i); } - - this.worldObj.addBlockEvent(TileEntityMobSpawner.this.pos, Blocks.mob_spawner, 1, 0); } public void readTags(TagObject nbt) { super.readTags(nbt); - this.mobID = nbt.getString("EntityId"); this.spawnDelay = nbt.getShort("Delay"); if (nbt.hasShort("MinSpawnDelay")) { this.minSpawnDelay = nbt.getShort("MinSpawnDelay"); this.maxSpawnDelay = nbt.getShort("MaxSpawnDelay"); - this.spawnCount = nbt.getShort("SpawnCount"); - } - - if (nbt.hasShort("MaxNearbyEntities")) - { - this.maxNearbyEntities = nbt.getShort("MaxNearbyEntities"); - this.activatingRangeFromPlayer = nbt.getShort("RequiredPlayerRange"); } if (nbt.hasShort("SpawnRange")) { this.spawnRange = nbt.getShort("SpawnRange"); } - - if (this.worldObj != null) - { - this.cachedEntity = null; - } } public void writeTags(TagObject nbt) { super.writeTags(nbt); - String s = this.mobID; - - if (s != null && !s.isEmpty()) - { - nbt.setString("EntityId", s); - nbt.setShort("Delay", (short)this.spawnDelay); - nbt.setShort("MinSpawnDelay", (short)this.minSpawnDelay); - nbt.setShort("MaxSpawnDelay", (short)this.maxSpawnDelay); - nbt.setShort("SpawnCount", (short)this.spawnCount); - nbt.setShort("MaxNearbyEntities", (short)this.maxNearbyEntities); - nbt.setShort("RequiredPlayerRange", (short)this.activatingRangeFromPlayer); - nbt.setShort("SpawnRange", (short)this.spawnRange); - } - } - - public Entity createRenderEntity(World worldIn) - { - if (this.cachedEntity == null) - { - this.cachedEntity = EntityRegistry.createEntityByName(this.mobID, worldIn); - -// if (entity != null) -// { -//// entity = this.spawnNewEntity(entity, false); -// this.cachedEntity = entity; -// } - } - - return this.cachedEntity; - } - - public double getMobRotation() - { - return this.mobRotation; - } - - public double getPrevMobRotation() - { - return this.prevMobRotation; - } - - public void setEntityName(String name) - { - this.mobID = name; + nbt.setShort("Delay", (short)this.spawnDelay); + nbt.setShort("MinSpawnDelay", (short)this.minSpawnDelay); + nbt.setShort("MaxSpawnDelay", (short)this.maxSpawnDelay); + nbt.setShort("SpawnRange", (short)this.spawnRange); } } diff --git a/common/src/main/java/common/tileentity/TileEntityTianReactor.java b/common/src/main/java/common/tileentity/TileEntityTianReactor.java index 17b8703..f276bde 100755 --- a/common/src/main/java/common/tileentity/TileEntityTianReactor.java +++ b/common/src/main/java/common/tileentity/TileEntityTianReactor.java @@ -3,6 +3,7 @@ package common.tileentity; import common.init.Blocks; import common.init.ItemRegistry; import common.init.Items; +import common.inventory.ContainerTile; import common.item.ItemStack; import common.tileentity.MachineResource.Type; @@ -46,7 +47,7 @@ public class TileEntityTianReactor extends TileEntityDevice { return "tian_reactor"; } - public String formatDisplay() { + public String formatDisplay(ContainerTile inv) { return String.format("Gespeicherte Energie: %d TF", this.getResource(0).getValue()); } diff --git a/server/src/main/java/server/vars/SVars.java b/server/src/main/java/server/vars/SVars.java index 50518ba..7d5a0f2 100644 --- a/server/src/main/java/server/vars/SVars.java +++ b/server/src/main/java/server/vars/SVars.java @@ -11,7 +11,13 @@ public abstract class SVars extends Vars { @Var(name = "spawnVillagers") public static boolean spawnVillager = true; @Var(name = "spawnCagedVillagers") - public static boolean spawnCagedVillager = true; + public static boolean spawnCageMobs = true; + @Var(name = "spawnBridgeMages") + public static boolean spawnBridgeMobs = true; + @Var(name = "spawnMineshaftArachnoids") + public static boolean spawnMineshaftMobs = true; + @Var(name = "spawnStrongholdHaunters") + public static boolean spawnStrongholdMobs = true; @Var(name = "spawnHutMages") public static boolean spawnHutMage = true; @Var(name = "daylightCycle") @@ -82,6 +88,8 @@ public abstract class SVars extends Vars { public static int minPassLength = 8; @Var(name = "port", min = 1024, max = 32767, nonDefault = true) public static int port = -1; + @Var(name = "spawnDungeonMobs") + public static int spawnDungeonMobs = 4; @Var(name = "gravity") public static float gravity = 1.0f; diff --git a/server/src/main/java/server/world/Converter.java b/server/src/main/java/server/world/Converter.java index b6b79cb..7b7bc10 100644 --- a/server/src/main/java/server/world/Converter.java +++ b/server/src/main/java/server/world/Converter.java @@ -78,7 +78,6 @@ import common.tileentity.TileEntityDropper; import common.tileentity.TileEntityEnchantmentTable; import common.tileentity.TileEntityFurnace; import common.tileentity.TileEntityHopper; -import common.tileentity.TileEntityMobSpawner; import common.tileentity.TileEntitySign; import common.util.Facing; import common.util.NibbleArray; @@ -343,7 +342,6 @@ public abstract class Converter { mapTile(TileEntityDispenser.class, "Trap", "dispenser"); mapTile(TileEntityDropper.class, "Dropper", "dropper"); mapTile(TileEntitySign.class, "Sign", "sign"); - mapTile(TileEntityMobSpawner.class, "MobSpawner", "mob_spawner"); // mapTile(TileEntityPiston.class, "Piston", "piston"); mapTile(TileEntityEnchantmentTable.class, "EnchantTable", "enchanting_table"); mapTile(TileEntityBeacon.class, "Beacon", "beacon"); @@ -576,7 +574,7 @@ public abstract class Converter { return Blocks.fire.getState().withProperty(BlockFire.AGE, data); } }, 51); - mapBlock(Blocks.mob_spawner, 52); + mapBlock(Blocks.iron_bars, 52); mapBlockData(Blocks.oak_stairs, 53); mapBlockData(Blocks.chest, 54); mapBlockData(Blocks.redstone, 55); diff --git a/server/src/main/java/server/worldgen/FeatureDungeons.java b/server/src/main/java/server/worldgen/FeatureDungeons.java index 9eeb4e3..719f09b 100755 --- a/server/src/main/java/server/worldgen/FeatureDungeons.java +++ b/server/src/main/java/server/worldgen/FeatureDungeons.java @@ -1,22 +1,28 @@ package server.worldgen; +import java.lang.reflect.InvocationTargetException; + import common.block.Material; +import common.entity.npc.EntityArachnoid; +import common.entity.npc.EntityUndead; +import common.entity.npc.EntityZombie; +import common.entity.types.EntityLiving; import common.init.Blocks; import common.init.Items; import common.item.RngLoot; -import common.log.Log; import common.rng.Random; import common.rng.WeightedList; import common.tileentity.TileEntity; import common.tileentity.TileEntityChest; -import common.tileentity.TileEntityMobSpawner; import common.util.BlockPos; import common.util.Facing; +import common.world.World; +import server.vars.SVars; import server.world.WorldServer; public class FeatureDungeons { - private static final String[] SPAWNERTYPES = new String[] {"Undead", "Zombie", "Zombie", "Arachnoid"}; + private static final Class[] MOB_TYPES = new Class[] {EntityUndead.class, EntityZombie.class, EntityZombie.class, EntityArachnoid.class}; private final int chance; @@ -148,16 +154,15 @@ public class FeatureDungeons } } - worldIn.setState(position, Blocks.mob_spawner.getState(), 2); - TileEntity tileentity = worldIn.getTileEntity(position); - - if (tileentity instanceof TileEntityMobSpawner) - { - ((TileEntityMobSpawner)tileentity).setEntityName(this.pickMobSpawner(rand)); - } - else - { - Log.TICK.warn("Konnte kein Mob-Spawner-Objekt bei (" + position.getX() + ", " + position.getY() + ", " + position.getZ() + ") erstellen"); + if(SVars.mobs && SVars.spawnDungeonMobs > 0) { + for(int z = 0; z < SVars.spawnDungeonMobs; z++) { + EntityLiving entity = this.pickMobSpawner(rand, worldIn); + entity.setLocationAndAngles((double)position.getX() + rand.doublev(), (double)position.getY(), (double)position.getZ() + rand.doublev(), worldIn.rand.floatv() * 360.0F, 0.0F); + entity.onInitialSpawn(null); + worldIn.spawnEntityInWorld(entity); + if(rand.chance(5)) + break; + } } return true; @@ -168,11 +173,13 @@ public class FeatureDungeons } } - /** - * Randomly decides which spawner to use in a dungeon - */ - private String pickMobSpawner(Random p_76543_1_) + private EntityLiving pickMobSpawner(Random rand, WorldServer world) { - return SPAWNERTYPES[p_76543_1_.zrange(SPAWNERTYPES.length)]; + try { + return rand.pick(MOB_TYPES).getConstructor(World.class).newInstance(world); + } + catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new RuntimeException(e); + } } } diff --git a/server/src/main/java/server/worldgen/structure/StructureBridge.java b/server/src/main/java/server/worldgen/structure/StructureBridge.java index 8af531e..42ccbd3 100755 --- a/server/src/main/java/server/worldgen/structure/StructureBridge.java +++ b/server/src/main/java/server/worldgen/structure/StructureBridge.java @@ -3,13 +3,13 @@ package server.worldgen.structure; import java.util.List; import common.collect.Lists; +import common.entity.npc.EntityDarkMage; import common.init.Blocks; import common.rng.Random; import common.tags.TagObject; -import common.tileentity.TileEntity; -import common.tileentity.TileEntityMobSpawner; import common.util.BlockPos; import common.util.Facing; +import server.vars.SVars; import server.world.WorldServer; import server.worldgen.LootConstants; @@ -1364,20 +1364,17 @@ public class StructureBridge this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 6, 8, 5, 7, 8, Blocks.blood_brick_fence.getState(), Blocks.blood_brick_fence.getState(), false); this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 8, 8, 4, 8, 8, Blocks.blood_brick_fence.getState(), Blocks.blood_brick_fence.getState(), false); - if (!this.hasSpawner) + if (!this.hasSpawner && SVars.mobs && SVars.spawnBridgeMobs) { BlockPos blockpos = new BlockPos(this.getXWithOffset(3, 5), this.getYWithOffset(5), this.getZWithOffset(3, 5)); if (structureBoundingBoxIn.isVecInside(blockpos)) { this.hasSpawner = true; - worldIn.setState(blockpos, Blocks.mob_spawner.getState(), 2); - TileEntity tileentity = worldIn.getTileEntity(blockpos); - - if (tileentity instanceof TileEntityMobSpawner) - { - ((TileEntityMobSpawner)tileentity).setEntityName("DarkMage"); - } + EntityDarkMage entity = new EntityDarkMage(worldIn); + entity.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)blockpos.getY(), (double)blockpos.getZ() + 0.5D, worldIn.rand.floatv() * 360.0F, 0.0F); + entity.onInitialSpawn(null); + worldIn.spawnEntityInWorld(entity); } } diff --git a/server/src/main/java/server/worldgen/structure/StructureMineshaft.java b/server/src/main/java/server/worldgen/structure/StructureMineshaft.java index a586573..7ede565 100755 --- a/server/src/main/java/server/worldgen/structure/StructureMineshaft.java +++ b/server/src/main/java/server/worldgen/structure/StructureMineshaft.java @@ -4,17 +4,17 @@ import java.util.LinkedList; import java.util.List; import common.entity.item.EntityChestCart; +import common.entity.npc.EntityArachnoid; import common.init.Blocks; import common.init.Items; import common.item.RngLoot; import common.rng.Random; import common.rng.WeightedList; import common.tags.TagObject; -import common.tileentity.TileEntity; -import common.tileentity.TileEntityMobSpawner; import common.util.BlockPos; import common.util.Facing; import common.world.State; +import server.vars.SVars; import server.world.WorldServer; import server.worldgen.LootConstants; @@ -360,7 +360,7 @@ public class StructureMineshaft this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, RngLoot.addToList(LootConstants.MINESHAFT_CHEST, Items.enchanted_book.getRandom(randomIn)), 3 + randomIn.zrange(4)); } - if (this.hasSpiders && !this.spawnerPlaced) + if (this.hasSpiders && !this.spawnerPlaced && SVars.mobs && SVars.spawnMineshaftMobs) { int l1 = this.getYWithOffset(0); int i2 = k1 - 1 + randomIn.zrange(3); @@ -371,13 +371,10 @@ public class StructureMineshaft if (structureBoundingBoxIn.isVecInside(blockpos)) { this.spawnerPlaced = true; - worldIn.setState(blockpos, Blocks.mob_spawner.getState(), 2); - TileEntity tileentity = worldIn.getTileEntity(blockpos); - - if (tileentity instanceof TileEntityMobSpawner) - { - ((TileEntityMobSpawner)tileentity).setEntityName("Arachnoid"); - } + EntityArachnoid entity = new EntityArachnoid(worldIn); + entity.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)blockpos.getY(), (double)blockpos.getZ() + 0.5D, worldIn.rand.floatv() * 360.0F, 0.0F); + entity.onInitialSpawn(null); + worldIn.spawnEntityInWorld(entity); } } } diff --git a/server/src/main/java/server/worldgen/structure/StructureStronghold.java b/server/src/main/java/server/worldgen/structure/StructureStronghold.java index 870a53b..b96c6c4 100755 --- a/server/src/main/java/server/worldgen/structure/StructureStronghold.java +++ b/server/src/main/java/server/worldgen/structure/StructureStronghold.java @@ -7,15 +7,15 @@ import common.block.artificial.BlockSlab; import common.block.artificial.BlockStoneBrick; import common.collect.Lists; import common.collect.Maps; +import common.entity.npc.EntityHaunter; import common.init.Blocks; import common.init.Items; import common.item.RngLoot; import common.rng.Random; import common.tags.TagObject; -import common.tileentity.TileEntity; -import common.tileentity.TileEntityMobSpawner; import common.util.BlockPos; import common.util.Facing; +import server.vars.SVars; import server.world.WorldServer; import server.worldgen.LootConstants; @@ -899,7 +899,7 @@ public class StructureStronghold // this.setBlockState(worldIn, Blocks.end_portal_frame.getStateFromMeta(j1).withProperty(BlockPortalFrame.ORB, Boolean.valueOf(randomIn.floatv() > 0.9F)), 7, 3, 10, structureBoundingBoxIn); // this.setBlockState(worldIn, Blocks.end_portal_frame.getStateFromMeta(j1).withProperty(BlockPortalFrame.ORB, Boolean.valueOf(randomIn.floatv() > 0.9F)), 7, 3, 11, structureBoundingBoxIn); - if (!this.hasSpawner) + if (!this.hasSpawner && SVars.mobs && SVars.spawnStrongholdMobs) { i = this.getYWithOffset(3); BlockPos blockpos = new BlockPos(this.getXWithOffset(5, 6), i, this.getZWithOffset(5, 6)); @@ -907,13 +907,10 @@ public class StructureStronghold if (structureBoundingBoxIn.isVecInside(blockpos)) { this.hasSpawner = true; - worldIn.setState(blockpos, Blocks.mob_spawner.getState(), 2); - TileEntity tileentity = worldIn.getTileEntity(blockpos); - - if (tileentity instanceof TileEntityMobSpawner) - { - ((TileEntityMobSpawner)tileentity).setEntityName("Haunter"); - } + EntityHaunter entity = new EntityHaunter(worldIn); + entity.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.0D, (double)blockpos.getZ() + 0.5D, worldIn.rand.floatv() * 360.0F, 0.0F); + entity.onInitialSpawn(null); + worldIn.spawnEntityInWorld(entity); } } diff --git a/server/src/main/java/server/worldgen/structure/StructureVillage.java b/server/src/main/java/server/worldgen/structure/StructureVillage.java index d16ea42..d88fb76 100755 --- a/server/src/main/java/server/worldgen/structure/StructureVillage.java +++ b/server/src/main/java/server/worldgen/structure/StructureVillage.java @@ -1921,7 +1921,7 @@ public class StructureVillage protected void spawnVillager(WorldServer worldIn, StructureBoundingBox p_74893_2_, int x, int y, int z) { - if (!this.villagerSpawned && SVars.mobs && SVars.spawnCagedVillager) + if (!this.villagerSpawned && SVars.mobs && SVars.spawnCageMobs) { int j = this.getXWithOffset(x, z); int k = this.getYWithOffset(y);