use of net.minecraft.block.BlockPortal in project BloodMagic by WayofTime.
the class Utils method swapLocations.
public static boolean swapLocations(World initialWorld, BlockPos initialPos, World finalWorld, BlockPos finalPos, boolean playSound) {
TileEntity initialTile = initialWorld.getTileEntity(initialPos);
TileEntity finalTile = finalWorld.getTileEntity(finalPos);
NBTTagCompound initialTag = new NBTTagCompound();
NBTTagCompound finalTag = new NBTTagCompound();
if (initialTile != null)
initialTile.writeToNBT(initialTag);
if (finalTile != null)
finalTile.writeToNBT(finalTag);
IBlockState initialState = initialWorld.getBlockState(initialPos);
IBlockState finalState = finalWorld.getBlockState(finalPos);
if ((initialState.getBlock().equals(Blocks.AIR) && finalState.getBlock().equals(Blocks.AIR)) || initialState.getBlock() instanceof BlockPortal || finalState.getBlock() instanceof BlockPortal)
return false;
if (playSound) {
initialWorld.playSound(initialPos.getX(), initialPos.getY(), initialPos.getZ(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
finalWorld.playSound(finalPos.getX(), finalPos.getY(), finalPos.getZ(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
}
// Finally, we get to do something! (CLEARING TILES)
if (finalState.getBlock().hasTileEntity(finalState))
finalWorld.removeTileEntity(finalPos);
if (initialState.getBlock().hasTileEntity(initialState))
initialWorld.removeTileEntity(initialPos);
// TILES CLEARED
IBlockState initialBlockState = initialWorld.getBlockState(initialPos);
IBlockState finalBlockState = finalWorld.getBlockState(finalPos);
finalWorld.setBlockState(finalPos, initialBlockState, 3);
if (initialTile != null) {
TileEntity newTileInitial = TileEntity.create(finalWorld, initialTag);
finalWorld.setTileEntity(finalPos, newTileInitial);
newTileInitial.setPos(finalPos);
newTileInitial.setWorld(finalWorld);
}
initialWorld.setBlockState(initialPos, finalBlockState, 3);
if (finalTile != null) {
TileEntity newTileFinal = TileEntity.create(initialWorld, finalTag);
initialWorld.setTileEntity(initialPos, newTileFinal);
newTileFinal.setPos(initialPos);
newTileFinal.setWorld(initialWorld);
}
initialWorld.notifyNeighborsOfStateChange(initialPos, finalState.getBlock(), true);
finalWorld.notifyNeighborsOfStateChange(finalPos, initialState.getBlock(), true);
return true;
}
use of net.minecraft.block.BlockPortal in project BloodMagic by WayofTime.
the class BlockTeleposer method swapBlocks.
public static boolean swapBlocks(Object caller, World worldI, World worldF, int xi, int yi, int zi, int xf, int yf, int zf, boolean doSound, int flag) {
TileEntity tileEntityI = worldI.getTileEntity(xi, yi, zi);
TileEntity tileEntityF = worldF.getTileEntity(xf, yf, zf);
NBTTagCompound nbttag1 = new NBTTagCompound();
NBTTagCompound nbttag2 = new NBTTagCompound();
if (tileEntityI != null) {
tileEntityI.writeToNBT(nbttag1);
}
if (tileEntityF != null) {
tileEntityF.writeToNBT(nbttag2);
}
Block blockI = worldI.getBlock(xi, yi, zi);
Block blockF = worldF.getBlock(xf, yf, zf);
if (blockI.equals(Blocks.air) && blockF.equals(Blocks.air)) {
return false;
}
if (blockI instanceof BlockMobSpawner || blockF instanceof BlockMobSpawner || caller instanceof TEDemonPortal ? false : blockI instanceof BlockPortal || blockF instanceof BlockPortal) {
return false;
}
int metaI = worldI.getBlockMetadata(xi, yi, zi);
int metaF = worldF.getBlockMetadata(xf, yf, zf);
TeleposeEvent evt = new TeleposeEvent(worldI, xi, yi, zi, blockI, metaI, worldF, xf, yf, zf, blockF, metaF);
if (MinecraftForge.EVENT_BUS.post(evt))
return false;
if (doSound) {
worldI.playSoundEffect(xi, yi, zi, "mob.endermen.portal", 1.0F, 1.0F);
worldF.playSoundEffect(xf, yf, zf, "mob.endermen.portal", 1.0F, 1.0F);
}
// CLEAR TILES
Block finalBlock = blockF;
if (finalBlock != null) {
TileEntity tileToSet = finalBlock.createTileEntity(worldF, metaF);
worldF.setTileEntity(xf, yf, zf, tileToSet);
}
if (blockI != null) {
TileEntity tileToSet = blockI.createTileEntity(worldI, metaI);
worldI.setTileEntity(xi, yi, zi, tileToSet);
}
// TILES CLEARED
worldF.setBlock(xf, yf, zf, blockI, metaI, flag);
if (tileEntityI != null) {
TileEntity newTileEntityI = TileEntity.createAndLoadEntity(nbttag1);
if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityI)) {
newTileEntityI = createMultipartFromNBT(worldF, nbttag1);
}
worldF.setTileEntity(xf, yf, zf, newTileEntityI);
newTileEntityI.xCoord = xf;
newTileEntityI.yCoord = yf;
newTileEntityI.zCoord = zf;
if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityI)) {
sendDescriptorOfTile(worldF, newTileEntityI);
}
}
worldI.setBlock(xi, yi, zi, finalBlock, metaF, flag);
if (tileEntityF != null) {
TileEntity newTileEntityF = TileEntity.createAndLoadEntity(nbttag2);
if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityF)) {
newTileEntityF = createMultipartFromNBT(worldI, nbttag2);
}
worldI.setTileEntity(xi, yi, zi, newTileEntityF);
newTileEntityF.xCoord = xi;
newTileEntityF.yCoord = yi;
newTileEntityF.zCoord = zi;
if (AlchemicalWizardry.isFMPLoaded && isMultipart(tileEntityF)) {
sendDescriptorOfTile(worldI, newTileEntityF);
}
}
return true;
}
Aggregations