use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.
the class TeleporterUtility method transferEntityToDimension.
/**
* Transfers an entity to a different dimension and location, as if it was being teleported by a dimension portal
*/
private static boolean transferEntityToDimension(Entity entity, double x, double y, double z, float yaw, float pitch, int dimension) {
MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
WorldServer srcWorld = minecraftServer.worldServerForDimension(entity.dimension);
WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
if (dstWorld != null) {
NBTTagCompound nbttagcompound = entity.writeToNBT(new NBTTagCompound());
nbttagcompound.removeTag("Dimension");
srcWorld.removeEntity(entity);
Entity newEntity = EntityList.newEntity(entity.getClass(), dstWorld);
newEntity.readFromNBT(nbttagcompound);
setEntityPosition(newEntity, x, y, z, yaw, pitch);
dstWorld.spawnEntity(newEntity);
dstWorld.updateEntityWithOptionalForce(newEntity, false);
return true;
} else {
return false;
}
}
use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.
the class BlockTeleporter method onEntityWalk.
@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
TeleporterNode destinationNode = null;
IBlockState state = world.getBlockState(pos);
EnumType type = EnumType.byMetadata(getMetaFromState(state));
if (entity instanceof EntityLivingBase && entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
ITeleportHandler teleportHandler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
if (!world.isRemote) {
if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
teleportHandler.setOnTeleporter(entity.getPosition().distanceSq(pos) <= 1);
teleportHandler.setDimension(entity.dimension);
if (teleportHandler.getOnTeleporter()) {
boolean isHostile = (entity instanceof EntityMob) || (entity instanceof EntityWolf && ((EntityWolf) entity).isAngry());
boolean isPassive = (entity instanceof EntityAnimal);
if ((isHostile == false || isHostile == ModConfiguration.teleportHostileMobs) && (isPassive == false || isPassive == ModConfiguration.teleportPassiveMobs)) {
destinationNode = TeleporterUtility.teleport((EntityLivingBase) entity, pos);
}
}
}
}
if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
TileEntityTeleporter tEnt = (TileEntityTeleporter) world.getTileEntity(pos);
if (tEnt != null) {
tEnt.spawnParticles();
}
}
if (type.isRecall() && entity instanceof EntityPlayerMP && destinationNode != null) {
WorldServer nextWorld = world.getMinecraftServer().worldServerForDimension(destinationNode.dimension);
breakBlockRecall(world, nextWorld, pos, destinationNode.pos, state, (EntityPlayerMP) entity);
}
}
}
use of net.minecraft.world.WorldServer in project RFToolsDimensions by McJty.
the class DimensionEditorTileEntity method update.
@Override
public void update() {
if (getWorld().isRemote) {
return;
}
ItemStack injectableItemStack = validateInjectableItemStack();
if (injectableItemStack.isEmpty()) {
return;
}
ItemStack dimensionItemStack = validateDimensionItemStack();
if (dimensionItemStack.isEmpty()) {
return;
}
if (ticksLeft == -1) {
// We were not injecting. Start now.
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
int id = dimensionItemStack.getTagCompound().getInteger("id");
if (dimensionManager.getDimensionInformation(id).isCheater()) {
ticksCost = 1;
rfPerTick = 0;
} else if (isMatterReceiver(injectableItemStack)) {
ticksCost = DimletCosts.baseDimensionTickCost + 1000;
rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
} else if (isTNT(injectableItemStack)) {
ticksCost = 600;
rfPerTick = 10;
} else {
DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
Settings settings = KnownDimletConfiguration.getSettings(key);
if (DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_CHEATER) {
ticksCost = 1;
rfPerTick = 0;
} else {
ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
}
}
ticksLeft = ticksCost;
} else {
int rf = getEnergyStored();
int rfpt = rfPerTick;
rfpt = (int) (rfpt * (2.0f - getInfusedFactor()) / 2.0f);
if (rf >= rfpt) {
// Enough energy.
consumeEnergy(rfpt);
ticksLeft--;
if (ticksLeft <= 0) {
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
NBTTagCompound tagCompound = dimensionItemStack.getTagCompound();
int id = tagCompound.getInteger("id");
if (isMatterReceiver(injectableItemStack)) {
World dimWorld = RfToolsDimensionManager.getWorldForDimension(getWorld(), id);
int y = findGoodReceiverLocation(dimWorld);
if (y == -1) {
y = dimWorld.getHeight() / 2;
}
Item item = injectableItemStack.getItem();
if (item instanceof ItemBlock) {
ItemBlock itemBlock = (ItemBlock) item;
IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(injectableItemStack));
BlockPos pos = new BlockPos(8, y, 8);
dimWorld.setBlockState(pos, state, 2);
Block block = dimWorld.getBlockState(pos).getBlock();
// @todo @@@@@@@@@@@@@@ check if right?
block.onBlockActivated(dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.0F, 0.0F, 0.0F);
// block.onBlockPlaced(dimWorld, pos, EnumFacing.DOWN, 0, 0, 0, 0, null);
block.onBlockPlacedBy(dimWorld, pos, state, null, injectableItemStack);
dimWorld.setBlockToAir(pos.up());
dimWorld.setBlockToAir(pos.up(2));
}
} else if (isTNT(injectableItemStack)) {
safeDeleteDimension(id, dimensionItemStack);
} else {
DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
DimensionInformation information = dimensionManager.getDimensionInformation(id);
information.injectDimlet(key);
dimensionManager.save(getWorld());
}
inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
stopInjecting();
}
}
}
markDirty();
setState();
}
use of net.minecraft.world.WorldServer in project RFToolsDimensions by McJty.
the class RfToolsDimensionManager method touchSpawnChunk.
private void touchSpawnChunk(World world, int id) {
// Make sure world generation kicks in for at least one chunk so that our matter receiver
// is generated and registered.
WorldServer worldServerForDimension = world.getMinecraftServer().getWorld(id);
ChunkProviderServer providerServer = worldServerForDimension.getChunkProvider();
if (!providerServer.chunkExists(0, 0)) {
try {
providerServer.provideChunk(0, 0);
providerServer.chunkGenerator.populate(0, 0);
} catch (Exception e) {
Logging.logError("Something went wrong during creation of the dimension!");
e.printStackTrace();
// We catch this exception to make sure our dimension tab is at least ok.
}
}
}
use of net.minecraft.world.WorldServer in project MorePlanets by SteveKunG.
the class TeleportUtil method teleportEntityInternational.
private static Entity teleportEntityInternational(Entity entity, MinecraftServer server, int sourceDim, int targetDim, double xCoord, double yCoord, double zCoord, float yaw, float pitch) {
if (entity.isDead) {
return null;
}
WorldServer sourceWorld = server.getWorld(sourceDim);
WorldServer targetWorld = server.getWorld(targetDim);
// Set the entity dead before calling changeDimension. Still need to call changeDimension for things like minecarts which will drop their contents otherwise.
if (!entity.isDead && entity instanceof EntityMinecart) {
entity.isDead = true;
entity.changeDimension(targetDim);
entity.isDead = false;
}
entity.dimension = targetDim;
sourceWorld.removeEntity(entity);
entity.isDead = false;
entity.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
sourceWorld.updateEntityWithOptionalForce(entity, false);
Entity newEntity = EntityList.newEntity(entity.getClass(), targetWorld);
if (newEntity != null) {
newEntity.copyDataFromOld(entity);
newEntity.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
boolean flag = newEntity.forceSpawn;
newEntity.forceSpawn = true;
targetWorld.spawnEntity(newEntity);
newEntity.forceSpawn = flag;
targetWorld.updateEntityWithOptionalForce(newEntity, false);
}
entity.isDead = true;
sourceWorld.resetUpdateEntityTick();
targetWorld.resetUpdateEntityTick();
return newEntity;
}
Aggregations