本文整理汇总了Java中net.minecraft.tileentity.TileEntityMobSpawner.getPos方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntityMobSpawner.getPos方法的具体用法?Java TileEntityMobSpawner.getPos怎么用?Java TileEntityMobSpawner.getPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.tileentity.TileEntityMobSpawner
的用法示例。
在下文中一共展示了TileEntityMobSpawner.getPos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSpawners
import net.minecraft.tileentity.TileEntityMobSpawner; //导入方法依赖的package包/类
/**
* search in all loaded TileEntities for MobSpawners,
* when a new MobSpawner gets found, display its type and coordinates in chat.
* @param showKnown show already found spawners
*/
public static void findSpawners(boolean showKnown) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc == null || mc.theWorld == null || mc.theWorld.loadedTileEntityList == null)
return;
for (Object o : mc.theWorld.loadedTileEntityList) {
if (o.getClass() == TileEntityMobSpawner.class) {
final TileEntityMobSpawner spawnerTileEntity = (TileEntityMobSpawner) o;
final BlockPos spawnerPos = spawnerTileEntity.getPos();
if (showKnown || !foundSpawners.contains(spawnerPos)) {
if (!showKnown) foundSpawners.add(spawnerPos);
// tell player about newly found spawner
NBTTagCompound nbt = new NBTTagCompound();
spawnerTileEntity.writeToNBT(nbt);
final String entityId = nbt.getString("EntityId");
mc.thePlayer.addChatMessage(getSpawnerFoundChatMessage(spawnerPos, entityId));
}
}
}
}
示例2: onHarvestDropsEvent
import net.minecraft.tileentity.TileEntityMobSpawner; //导入方法依赖的package包/类
@SubscribeEvent
public static void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent evt) {
if (!evt.isCanceled() && evt.getState().getBlock() instanceof BlockMobSpawner) {
if (dropCache.containsKey(evt.getPos())) {
ItemStack stack = dropCache.get(evt.getPos());
if (Prep.isValid(stack)) {
evt.getDrops().add(stack);
dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
}
} else {
// A spawner was broken---but not by a player. The TE has been
// invalidated already, but we might be able to recover it.
try {
for (Object object : evt.getWorld().loadedTileEntityList) {
if (object instanceof TileEntityMobSpawner) {
TileEntityMobSpawner spawner = (TileEntityMobSpawner) object;
BlockPos p = spawner.getPos();
if (spawner.getWorld() == evt.getWorld() && p.equals(evt.getPos())) {
// Bingo!
MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic();
ResourceLocation entityName = getEntityName(logic);
if (entityName != null && !isBlackListed(entityName)) {
final CapturedMob capturedMob = CapturedMob.create(entityName);
if (capturedMob != null) {
evt.getDrops().add(capturedMob.toStack(ModObject.itemBrokenSpawner.getItemNN(), 0, 1));
}
}
}
}
}
} catch (Exception e) {
// Risky recovery failed. Happens.
}
}
}
}