2016-02-18 17:25:11 +01:00
|
|
|
package WayofTime.bloodmagic.block;
|
|
|
|
|
2017-08-14 20:53:42 -07:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2019-02-01 01:46:02 +01:00
|
|
|
import WayofTime.bloodmagic.block.base.BlockInteger;
|
2018-03-04 09:17:23 -08:00
|
|
|
import WayofTime.bloodmagic.ritual.IMasterRitualStone;
|
2019-02-01 01:46:02 +01:00
|
|
|
import WayofTime.bloodmagic.ritual.portal.LocationsHandler;
|
2018-02-15 18:49:01 -08:00
|
|
|
import WayofTime.bloodmagic.teleport.PortalLocation;
|
|
|
|
import WayofTime.bloodmagic.teleport.TeleportQueue;
|
2019-02-01 01:46:02 +01:00
|
|
|
import WayofTime.bloodmagic.teleport.Teleports;
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.tile.TileDimensionalPortal;
|
2019-09-22 12:55:43 -07:00
|
|
|
import net.minecraft.block.BlockState;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-18 17:12:34 -04:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.util.EnumParticleTypes;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
2017-01-02 00:10:28 -08:00
|
|
|
import javax.annotation.Nullable;
|
2017-08-15 21:30:48 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Random;
|
2017-01-02 00:10:28 -08:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class BlockDimensionalPortal extends BlockInteger {
|
2016-03-18 17:12:34 -04:00
|
|
|
protected static final AxisAlignedBB AABB_0 = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
|
|
|
|
protected static final AxisAlignedBB AABB_1 = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
|
|
|
|
protected static final AxisAlignedBB AABB_DEFAULT = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D);
|
2016-02-18 17:25:11 +01:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public BlockDimensionalPortal() {
|
2016-04-24 10:06:28 -07:00
|
|
|
super(Material.PORTAL, 2);
|
2019-01-31 19:10:37 -08:00
|
|
|
setTranslationKey(BloodMagic.MODID + ".dimensionalPortal");
|
2016-02-18 17:25:11 +01:00
|
|
|
setBlockUnbreakable();
|
|
|
|
setResistance(2000);
|
|
|
|
setLightOpacity(0);
|
|
|
|
}
|
|
|
|
|
2016-04-03 10:12:10 -04:00
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public boolean isNormalCube(BlockState state, IBlockAccess world, BlockPos pos) {
|
2016-04-03 10:12:10 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public boolean isOpaqueCube(BlockState state) {
|
2016-04-03 10:12:10 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public boolean causesSuffocation(BlockState state) {
|
2016-04-03 10:12:10 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public AxisAlignedBB getCollisionBoundingBox(BlockState state, IBlockAccess world, BlockPos pos) {
|
2016-02-18 17:25:11 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean isOpaqueCube() {
|
2016-02-18 17:25:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean isFullCube() {
|
2016-02-18 17:25:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public int getLightValue(BlockState state, IBlockAccess world, BlockPos pos) {
|
2016-02-18 17:25:11 +01:00
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public void onEntityCollision(World world, BlockPos pos, BlockState blockState, Entity entity) {
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!world.isRemote && world.getTileEntity(pos) instanceof TileDimensionalPortal) {
|
2016-02-18 17:25:11 +01:00
|
|
|
TileDimensionalPortal tile = (TileDimensionalPortal) world.getTileEntity(pos);
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (LocationsHandler.getLocationsHandler() != null) {
|
2016-02-18 17:25:11 +01:00
|
|
|
ArrayList<PortalLocation> linkedLocations = LocationsHandler.getLocationsHandler().getLinkedLocations(tile.portalID);
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (linkedLocations != null && !linkedLocations.isEmpty() && linkedLocations.size() > 1) {
|
|
|
|
if (world.getTileEntity(tile.getMasterStonePos()) != null && world.getTileEntity(tile.getMasterStonePos()) instanceof IMasterRitualStone) {
|
2016-02-21 13:26:09 -05:00
|
|
|
IMasterRitualStone masterRitualStone = (IMasterRitualStone) world.getTileEntity(tile.getMasterStonePos());
|
2017-08-15 21:30:48 -07:00
|
|
|
if (linkedLocations.get(0).equals(new PortalLocation(masterRitualStone.getBlockPos().up(), world.provider.getDimension()))) {
|
2016-02-18 17:25:11 +01:00
|
|
|
PortalLocation portal = linkedLocations.get(1);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (portal.getDimension() == world.provider.getDimension()) {
|
2016-05-21 12:57:04 -07:00
|
|
|
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), false));
|
2017-08-15 21:30:48 -07:00
|
|
|
} else {
|
2016-05-21 12:57:04 -07:00
|
|
|
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), world, portal.getDimension(), false));
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
} else if (linkedLocations.get(1).equals(new PortalLocation(masterRitualStone.getBlockPos().up(), world.provider.getDimension()))) {
|
2016-02-18 17:25:11 +01:00
|
|
|
PortalLocation portal = linkedLocations.get(0);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (portal.getDimension() == world.provider.getDimension()) {
|
2016-05-21 12:57:04 -07:00
|
|
|
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), false));
|
2017-08-15 21:30:48 -07:00
|
|
|
} else {
|
2016-05-21 12:57:04 -07:00
|
|
|
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(portal.getX(), portal.getY(), portal.getZ(), entity, masterRitualStone.getOwner(), world, portal.getDimension(), false));
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public int quantityDropped(Random par1Random) {
|
2016-02-18 17:25:11 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public AxisAlignedBB getBoundingBox(BlockState state, IBlockAccess world, BlockPos pos) {
|
2016-03-18 17:12:34 -04:00
|
|
|
int meta = state.getBlock().getMetaFromState(state);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (meta == 0) {
|
2016-03-18 17:12:34 -04:00
|
|
|
return AABB_0;
|
2017-08-15 21:30:48 -07:00
|
|
|
} else if (meta == 1) {
|
2016-03-18 17:12:34 -04:00
|
|
|
return AABB_1;
|
2017-08-15 21:30:48 -07:00
|
|
|
} else {
|
2016-03-18 17:12:34 -04:00
|
|
|
return AABB_DEFAULT;
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 17:12:34 -04:00
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void setBlockBoundsForItemRender()
|
|
|
|
// {
|
|
|
|
// setBlockBounds(0f, 0f, 0.375f, 1f, 1f, 0.625f);
|
|
|
|
// }
|
2016-02-18 17:25:11 +01:00
|
|
|
|
2016-03-18 17:12:34 -04:00
|
|
|
@Override
|
2016-02-18 17:25:11 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-01-31 19:10:37 -08:00
|
|
|
public BlockRenderLayer getRenderLayer() {
|
2016-03-18 17:12:34 -04:00
|
|
|
return BlockRenderLayer.TRANSLUCENT;
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2019-09-22 12:55:43 -07:00
|
|
|
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rand) {
|
2016-02-18 17:25:11 +01:00
|
|
|
this.spawnParticles(world, pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
}
|
|
|
|
|
2017-01-02 00:10:28 -08:00
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public boolean hasTileEntity(BlockState state) {
|
2017-01-02 00:10:28 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2019-09-22 12:55:43 -07:00
|
|
|
public TileEntity createTileEntity(World world, BlockState state) {
|
2017-01-02 00:10:28 -08:00
|
|
|
return new TileDimensionalPortal();
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
private void spawnParticles(World world, int x, int y, int z) {
|
2016-02-18 17:25:11 +01:00
|
|
|
Random random = world.rand;
|
|
|
|
double d0 = 0.0625D;
|
2017-08-15 21:30:48 -07:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
2016-02-18 17:25:11 +01:00
|
|
|
double particleX = (double) ((float) x + random.nextFloat());
|
|
|
|
double particleY = (double) ((float) y + random.nextFloat());
|
|
|
|
double particleZ = (double) ((float) z + random.nextFloat());
|
2017-08-15 21:30:48 -07:00
|
|
|
if (i == 0 && !world.getBlockState(new BlockPos(x, y + 1, z)).isOpaqueCube()) {
|
2016-02-18 17:25:11 +01:00
|
|
|
particleY = (double) (y + 1) + d0;
|
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (i == 1 && !world.getBlockState(new BlockPos(x, y - 1, z)).isOpaqueCube()) {
|
2016-02-18 17:25:11 +01:00
|
|
|
particleY = (double) y - d0;
|
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (i == 2 && !world.getBlockState(new BlockPos(x, y, z + 1)).isOpaqueCube()) {
|
2016-02-18 17:25:11 +01:00
|
|
|
particleZ = (double) (z + 1) + d0;
|
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (i == 3 && !world.getBlockState(new BlockPos(x, y, z - 1)).isOpaqueCube()) {
|
2016-02-18 17:25:11 +01:00
|
|
|
particleZ = (double) z - d0;
|
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (i == 4 && !world.getBlockState(new BlockPos(x + 1, y, z)).isOpaqueCube()) {
|
2016-02-18 17:25:11 +01:00
|
|
|
particleX = (double) (x + 1) + d0;
|
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (i == 5 && !world.getBlockState(new BlockPos(x - 1, y, z)).isOpaqueCube()) {
|
2016-02-18 17:25:11 +01:00
|
|
|
particleX = (double) x - d0;
|
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
if (particleX < (double) x || particleX > (double) (x + 1) || particleY < 0.0D || particleY > (double) (y + 1) || particleZ < (double) z || particleZ > (double) (z + 1)) {
|
2016-02-18 17:25:11 +01:00
|
|
|
world.spawnParticle(EnumParticleTypes.REDSTONE, particleX, particleY, particleZ, 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|