net.minecraft.tileentity.TileEntityMobSpawner Java Examples

The following examples show how to use net.minecraft.tileentity.TileEntityMobSpawner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Spawnable.java    From minecraft-roguelike with GNU General Public License v3.0 6 votes vote down vote up
public void generate(IWorldEditor editor, Random rand, Coord cursor, int level){
	Coord pos = new Coord(cursor);
	editor.setBlock(pos, new MetaBlock(Blocks.MOB_SPAWNER.getDefaultState()), true,	true);
	
	TileEntity tileentity = editor.getTileEntity(pos);
	if (!(tileentity instanceof TileEntityMobSpawner)) return;
	
	TileEntityMobSpawner spawner = (TileEntityMobSpawner)tileentity;
	MobSpawnerBaseLogic spawnerLogic = spawner.getSpawnerBaseLogic();
	
	NBTTagCompound nbt = new NBTTagCompound();
	nbt.setInteger("x", pos.getX());
	nbt.setInteger("y", pos.getY());
	nbt.setInteger("z", pos.getZ());
	
	nbt.setTag("SpawnPotentials", getSpawnPotentials(rand, level));
	
	spawnerLogic.readFromNBT(nbt);
	spawnerLogic.updateSpawner();
	tileentity.markDirty();
}
 
Example #2
Source File: ItemMobSpawner.java    From NotEnoughItems with MIT License 6 votes vote down vote up
/**
 * Called from BlockMobSpawner on the client via asm generated onBlockPlacedBy
 */
public static void onBlockPlaced(World world, BlockPos pos, ItemStack stack) {
    if (!NEIClientConfig.hasSMPCounterPart()) {
        return;
    }

    TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) world.getTileEntity(pos);
    if (tileentitymobspawner != null) {
        setDefaultTag(stack);
        String mobtype = IDtoNameMap.get(stack.getItemDamage());
        if (mobtype != null) {
            NEIClientPacketHandler.sendMobSpawnerID(pos.getX(), pos.getY(), pos.getZ(), mobtype);
            tileentitymobspawner.getSpawnerBaseLogic().setEntityId(new ResourceLocation(mobtype));
        }
    }
}
 
Example #3
Source File: SpawnerEspMod.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onRender(RenderEvent event) {
  event.getBuffer().begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
  
  for (TileEntity tileEntity : getWorld().loadedTileEntityList) {
    if (tileEntity instanceof TileEntityMobSpawner) {
      BlockPos pos = tileEntity.getPos();
      GeometryTessellator.drawCuboid(
          event.getBuffer(), pos, GeometryMasks.Line.ALL, Colors.RED.toBuffer());
    }
  }
  
  event.getTessellator().draw();
}
 
Example #4
Source File: BlockTrackEntryMobSpawner.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addInformation(World world, int x, int y, int z, TileEntity te, List<String> infoList){
    if(te instanceof TileEntityMobSpawner) {
        MobSpawnerBaseLogic spawner = ((TileEntityMobSpawner)te).func_145881_a();
        infoList.add("Spawner Type: " + StatCollector.translateToLocal("entity." + spawner.getEntityNameToSpawn() + ".name"));
        if(spawner.isActivated()) {
            infoList.add("Time until next spawn: " + PneumaticCraftUtils.convertTicksToMinutesAndSeconds(spawner.spawnDelay, false));
        } else if(HackableMobSpawner.isHacked(world, x, y, z)) {
            infoList.add("Spawner is hacked");
        } else {
            infoList.add("Spawner is standing by");
        }
    }

}
 
Example #5
Source File: HackableMobSpawner.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean afterHackTick(World world, int x, int y, int z){
    MobSpawnerBaseLogic spawner = ((TileEntityMobSpawner)world.getTileEntity(x, y, z)).func_145881_a();
    spawner.field_98284_d = spawner.field_98287_c;//oldRotation = rotation, to stop render glitching
    spawner.spawnDelay = 10;
    return false;
}
 
Example #6
Source File: NEIServerPacketHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private void handleMobSpawnerID(World world, BlockPos coord, String mobtype) {
    TileEntity tile = world.getTileEntity(coord);
    if (tile instanceof TileEntityMobSpawner) {
        ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityId(new ResourceLocation(mobtype));
        tile.markDirty();
        IBlockState state = world.getBlockState(coord);
        world.notifyBlockUpdate(coord, state, state, 4);
    }
}
 
Example #7
Source File: NEISPH.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private void handleMobSpawnerID(World world, BlockCoord coord, String mobtype) {
    TileEntity tile = world.getTileEntity(coord.pos());
    if (tile instanceof TileEntityMobSpawner) {
        ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityName(mobtype);
        tile.markDirty();
        world.markBlockForUpdate(coord.pos());
    }
}
 
Example #8
Source File: ItemMobSpawner.java    From NotEnoughItems with MIT License 5 votes vote down vote up
/**
 * Called from BlockMobSpawner on the client via asm generated onBlockPlacedBy
 */
public static void onBlockPlaced(World world, BlockPos pos, ItemStack stack) {
    if(!NEIClientConfig.hasSMPCounterPart())
        return;

    TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) world.getTileEntity(pos);
    if (tileentitymobspawner != null) {
        setDefaultTag(stack);
        String mobtype = IDtoNameMap.get(stack.getItemDamage());
        if (mobtype != null) {
            NEICPH.sendMobSpawnerID(pos.getX(), pos.getY(), pos.getZ(), mobtype);
            tileentitymobspawner.getSpawnerBaseLogic().setEntityName(mobtype);
        }
    }
}
 
Example #9
Source File: StructureJourneymanTower.java    From Artifacts with MIT License 4 votes vote down vote up
private static void basement(World world, int i, int j, int k, Random rand) {
	boolean noair = false;
	int y = -1;
	do {
		noair = false;
		for(int x = 1; x <= 9; x++) {
			for(int z = 0; z <= 8; z++) {
				//5,y,4
				int d = (x-5)*(x-5)+(z-4)*(z-4);
				if(d <= 17) {
					if(!world.getBlock(i+x, j+y, z+k).isOpaqueCube() || world.getBlock(i+x, j+y, z+k) == Blocks.leaves) {
						noair=true;
						world.setBlock(i+x, j+y, z+k, StructureGenHelper.cobbleOrMossy(rand), 0, 2);
					}
				}
			}
		}
		y--;
	} while(noair && (j+y) >= 0);
	if(y >= -7 && world.rand.nextBoolean()) {
		y = -8;
	}
	if(y < -7) {
		y++;
		int yy = 3;
		for(; yy <= 5; yy++) {
			for(int x = 3; x <= 7; x++) {
				for(int z = 2; z <= 6; z++) {
					world.setBlockToAir(i+x, j+y+yy, k+z);
				}
			}
		}
		world.setBlock(i+5, j+y+5, k+4, Blocks.mob_spawner, 0, 2);
		TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)world.getTileEntity(i+5, j+y+5, k+4);

           if (tileentitymobspawner != null)
           {
               tileentitymobspawner.func_145881_a/*getSpawnerLogic*/().setEntityName("ClayGolem");
               NBTTagCompound nbt = new NBTTagCompound();
               tileentitymobspawner.writeToNBT(nbt);
               nbt.setShort("MinSpawnDelay",(short)100);
               nbt.setShort("MaxSpawnDelay",(short)600);
               tileentitymobspawner.readFromNBT(nbt);
           }
           
           world.setBlock(i+5, j+y+4, k+4, StructureGenHelper.randomBlock(rand, new Block[]{Blocks.chest, Blocks.chest, Blocks.air}), 2, 2);
   		TileEntity te = world.getTileEntity(i+5, j+y+4, k+4);
   		if(te != null && te instanceof TileEntityChest) {
   			TileEntityChest tec = (TileEntityChest)te;
   			ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
               WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), tec, info.getCount(rand));
   		}
   		
   		world.setBlock(i+5, j+y+3, k+4, StructureGenHelper.cobbleOrMossy(rand), 0, 2);
           
		for(yy=3;yy*-1>y;yy++) {
			world.setBlock(i+7, j+y+yy, k+6, Blocks.ladder, 2, 2);
		}
		world.setBlock(i+7, j+y+yy, k+6, Blocks.ladder, 2, 2);
		world.setBlock(i+7, j+y+yy+1, k+6, Blocks.trapdoor, 2, 2);
	}
}
 
Example #10
Source File: StructureTofuMineshaftPieces.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes
 * Mineshafts at the end, it adds Fences...
 */
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) {
    if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) {
        return false;
    } else {

        int i1 = this.sectionCount * 5 - 1;
        IBlockState iblockstate = this.getPlanksBlock();
        this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 2, 1, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false);
        this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.8F, 0, 2, 0, 2, 2, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false, 0);

        if (this.hasSpiders) {
            this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.6F, 0, 0, 0, 2, 1, i1, Blocks.WEB.getDefaultState(), Blocks.AIR.getDefaultState(), false, 8);
        }

        for (int j1 = 0; j1 < this.sectionCount; ++j1) {
            int k1 = 2 + j1 * 5;
            this.placeSupport(worldIn, structureBoundingBoxIn, 0, 0, k1, 2, 2, randomIn);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 - 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 - 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 + 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 + 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 - 2);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 - 2);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 + 2);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 + 2);

            if (randomIn.nextInt(100) == 0) {
                this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 2, 0, k1 - 1, TofuLootTables.tofumineshaft);
            }

            if (randomIn.nextInt(100) == 0) {
                this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, TofuLootTables.tofumineshaft);
            }

            if (this.hasSpiders && !this.spawnerPlaced) {
                int l1 = this.getYWithOffset(0);
                int i2 = k1 - 1 + randomIn.nextInt(3);
                int j2 = this.getXWithOffset(1, i2);
                int k2 = this.getZWithOffset(1, i2);
                BlockPos blockpos = new BlockPos(j2, l1, k2);

                if (structureBoundingBoxIn.isVecInside(blockpos) && this.getSkyBrightness(worldIn, 1, 0, i2, structureBoundingBoxIn) < 8) {
                    this.spawnerPlaced = true;
                    worldIn.setBlockState(blockpos, Blocks.MOB_SPAWNER.getDefaultState(), 2);
                    TileEntity tileentity = worldIn.getTileEntity(blockpos);

                    if (tileentity instanceof TileEntityMobSpawner) {
                        ((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().setEntityId(EntityList.getKey(EntityTofuSpider.class));
                    }
                }
            }
        }

        for (int l2 = 0; l2 <= 2; ++l2) {
            for (int i3 = 0; i3 <= i1; ++i3) {
                IBlockState iblockstate3 = this.getBlockStateFromPos(worldIn, l2, -1, i3, structureBoundingBoxIn);

                if (iblockstate3.getMaterial() == Material.AIR && this.getSkyBrightness(worldIn, l2, -1, i3, structureBoundingBoxIn) < 8) {
                    this.setBlockState(worldIn, iblockstate, l2, -1, i3, structureBoundingBoxIn);
                }
            }
        }

        if (this.hasRails) {
            IBlockState iblockstate1 = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH);

            for (int j3 = 0; j3 <= i1; ++j3) {
                IBlockState iblockstate2 = this.getBlockStateFromPos(worldIn, 1, -1, j3, structureBoundingBoxIn);

                if (iblockstate2.getMaterial() != Material.AIR && iblockstate2.isFullBlock()) {
                    float f = this.getSkyBrightness(worldIn, 1, 0, j3, structureBoundingBoxIn) > 8 ? 0.9F : 0.7F;
                    this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, f, 1, 0, j3, iblockstate1);
                }
            }
        }

        return true;
    }
}
 
Example #11
Source File: ItemMysteriousPotato.java    From SimplyJetpacks with MIT License 4 votes vote down vote up
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int meta, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile instanceof TileEntityMobSpawner) {
            NBTTagCompound tag = new NBTTagCompound();
            tile.writeToNBT(tag);
            
            tag.setString("EntityId", "Zombie");
            
            NBTTagList spawnPotentials = new NBTTagList();
            NBTTagCompound zombieSpawn = new NBTTagCompound();
            
            zombieSpawn.setString("Type", "Zombie");
            zombieSpawn.setInteger("Weight", 1);
            
            NBTTagCompound zombieSpawnProperties = new NBTTagCompound();
            zombieSpawnProperties.setString("id", "Zombie");
            
            NBTTagList equipment = new NBTTagList();
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(ModItems.jetpackPotato.writeToNBT(new NBTTagCompound()));
            zombieSpawnProperties.setTag("Equipment", equipment);
            
            NBTTagList dropChances = new NBTTagList();
            for (int i = 0; i <= 4; i++) {
                dropChances.appendTag(new NBTTagFloat(0.0F));
            }
            zombieSpawnProperties.setTag("DropChances", dropChances);
            
            zombieSpawn.setTag("Properties", zombieSpawnProperties);
            spawnPotentials.appendTag(zombieSpawn);
            
            tag.setTag("SpawnPotentials", spawnPotentials);
            
            tag.setShort("SpawnCount", (short) 2);
            tag.setShort("SpawnRange", (short) 8);
            tag.setShort("Delay", (short) -1);
            tag.setShort("MinSpawnDelay", (short) 30);
            tag.setShort("MaxSpawnDelay", (short) 60);
            tag.setShort("MaxNearbyEntities", (short) 10);
            tag.setShort("RequiredPlayerRange", (short) 96);
            tile.readFromNBT(tag);
        }
    }
    return true;
}
 
Example #12
Source File: AdapterMobSpawner.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
private static MobSpawnerBaseLogic getSpawnerLogic(TileEntityMobSpawner spawner) {
	return spawner.func_145881_a();
}
 
Example #13
Source File: AdapterMobSpawner.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.STRING, description = "The name of the mob that spawns from the spawner")
public String getSpawningMobName(TileEntityMobSpawner spawner) {
	return getSpawnerLogic(spawner).getEntityNameToSpawn();
}
 
Example #14
Source File: AdapterMobSpawner.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Class<?> getTargetClass() {
	return TileEntityMobSpawner.class;
}
 
Example #15
Source File: CraftCreatureSpawner.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public CraftCreatureSpawner(final Block block) {
    super(block);

    spawner = (TileEntityMobSpawner) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ());
}
 
Example #16
Source File: MonolithGenerator.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
public void placeSpawner(World world, BlockPos pos) {
	setBlockAndNotifyAdequately(world, pos, Blocks.MOB_SPAWNER.getDefaultState());
	TileEntityMobSpawner theSpawner = (TileEntityMobSpawner) world.getTileEntity(pos);
	MobSpawnerBaseLogic logic = theSpawner.getSpawnerBaseLogic();
	logic.setEntityId(new ResourceLocation("magma_cube"));
}
 
Example #17
Source File: MageTowerGenerator.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
public static void placeSpawner(World world, BlockPos pos, String mob) {
	placeBlock(world, pos, Blocks.MOB_SPAWNER);
	TileEntityMobSpawner theSpawner = (TileEntityMobSpawner) world.getTileEntity(pos);
	MobSpawnerBaseLogic logic = theSpawner.getSpawnerBaseLogic();
	logic.setEntityId(new ResourceLocation(mob));
}
 
Example #18
Source File: CraftCreatureSpawner.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftCreatureSpawner(final Material material, TileEntityMobSpawner te) {
    super(material, te);
}
 
Example #19
Source File: CraftCreatureSpawner.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftCreatureSpawner(final Block block) {
    super(block, TileEntityMobSpawner.class);
}