diff --git a/src/main/java/mekanism/common/MekanismBlocks.java b/src/main/java/mekanism/common/MekanismBlocks.java index be3f61572..e422241b8 100644 --- a/src/main/java/mekanism/common/MekanismBlocks.java +++ b/src/main/java/mekanism/common/MekanismBlocks.java @@ -86,6 +86,7 @@ public class MekanismBlocks { registry.register(init(RoadPlasticBlock, "RoadPlasticBlock")); registry.register(init(PlasticFence, "PlasticFence")); registry.register(init(SaltBlock, "SaltBlock")); + registry.register(BlockBasic.BlockPortalOverride.instance); } /** diff --git a/src/main/java/mekanism/common/block/BlockBasic.java b/src/main/java/mekanism/common/block/BlockBasic.java index 0dd8f0baf..c877664d0 100644 --- a/src/main/java/mekanism/common/block/BlockBasic.java +++ b/src/main/java/mekanism/common/block/BlockBasic.java @@ -1,5 +1,6 @@ package mekanism.common.block; +import com.google.common.cache.LoadingCache; import java.util.Objects; import java.util.UUID; import javax.annotation.Nonnull; @@ -39,10 +40,15 @@ import mekanism.common.util.MekanismUtils; import mekanism.common.util.SecurityUtils; import mekanism.common.util.StackUtils; import net.minecraft.block.Block; +import net.minecraft.block.BlockFire; +import net.minecraft.block.BlockPortal; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.BlockWorldState; import net.minecraft.block.state.IBlockState; +import net.minecraft.block.state.pattern.BlockPattern; +import net.minecraft.block.state.pattern.BlockPattern.PatternHelper; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving.SpawnPlacementType; @@ -50,14 +56,18 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumFacing.Axis; +import net.minecraft.util.EnumFacing.AxisDirection; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; @@ -67,10 +77,14 @@ import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -244,6 +258,10 @@ public abstract class BlockBasic extends BlockTileDrops { if (tileEntity instanceof IStructuralMultiblock) { ((IStructuralMultiblock) tileEntity).doUpdate(); } + Block newBlock = world.getBlockState(fromPos).getBlock(); + if (BasicBlockType.get(state) == BasicBlockType.REFINED_OBSIDIAN && newBlock instanceof BlockFire) { + BlockPortalOverride.instance.trySpawnPortal(world, fromPos); + } } } @@ -475,7 +493,8 @@ public abstract class BlockBasic extends BlockTileDrops { @Override @Deprecated public boolean isFullCube(IBlockState state) { - return false; + BasicBlockType type = BasicBlockType.get(state); + return type != null && type.isFullBlock; } @Nonnull @@ -690,4 +709,167 @@ public abstract class BlockBasic extends BlockTileDrops { } return 0; } + + public static class Size extends BlockPortal.Size { + + private int portalBlockCount; + + public Size(World world, BlockPos pos, Axis axis) { + super(world, pos, axis); + } + + private boolean isFrame(IBlockState state) { + Block block = state.getBlock(); + BasicBlockType type = null; + if (block instanceof BlockBasic) { + type = BasicBlockType.get(state); + } + return block == Blocks.OBSIDIAN || type == BasicBlockType.REFINED_OBSIDIAN; + } + + protected int getDistanceUntilEdge(BlockPos pos, @Nonnull EnumFacing facing) { + int i; + for (i = 0; i < 22; ++i) { + BlockPos blockpos = pos.offset(facing, i); + if (!this.isEmptyBlock(this.world.getBlockState(blockpos).getBlock()) || !isFrame(this.world.getBlockState(blockpos.down()))) { + break; + } + } + return isFrame(this.world.getBlockState(pos.offset(facing, i))) ? i : 0; + } + + protected int calculatePortalHeight() { + label56: + for (this.height = 0; this.height < 21; ++this.height) { + for (int i = 0; i < this.width; ++i) { + BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i).up(this.height); + Block block = this.world.getBlockState(blockpos).getBlock(); + if (!this.isEmptyBlock(block)) { + break label56; + } + if (block == Blocks.PORTAL) { + ++this.portalBlockCount; + } + if (i == 0) { + if (!isFrame(this.world.getBlockState(blockpos.offset(this.leftDir)))) { + break label56; + } + } else if (i == this.width - 1) { + if (!isFrame(this.world.getBlockState(blockpos.offset(this.rightDir)))) { + break label56; + } + } + } + } + + for (int j = 0; j < this.width; ++j) { + if (!isFrame(this.world.getBlockState(this.bottomLeft.offset(this.rightDir, j).up(this.height)))) { + this.height = 0; + break; + } + } + if (this.height <= 21 && this.height >= 3) { + return this.height; + } + this.bottomLeft = null; + this.width = 0; + this.height = 0; + return 0; + } + } + + public static class BlockPortalOverride extends BlockPortal { + + public static final BlockPortalOverride instance = new BlockPortalOverride(); + + public BlockPortalOverride() { + super(); + setRegistryName(new ResourceLocation("minecraft", "portal")); + } + + @Nonnull + @Override + public PatternHelper createPatternHelper(@Nonnull World world, BlockPos pos) { + Axis axis = Axis.Z; + BlockBasic.Size size = new BlockBasic.Size(world, pos, Axis.X); + if (!size.isValid()) { + axis = Axis.X; + size = new BlockBasic.Size(world, pos, EnumFacing.Axis.Z); + } + LoadingCache loadingCache = BlockPattern.createLoadingCache(world, true); + if (!size.isValid()) { + return new PatternHelper(pos, EnumFacing.NORTH, EnumFacing.UP, loadingCache, 1, 1, 1); + } + int[] aint = new int[AxisDirection.values().length]; + EnumFacing enumfacing = size.rightDir.rotateYCCW(); + BlockPos blockpos = size.bottomLeft.up(size.getHeight() - 1); + + for (AxisDirection direction : AxisDirection.values()) { + PatternHelper patternHelper = new PatternHelper(enumfacing.getAxisDirection() == direction ? blockpos : blockpos.offset(size.rightDir, size.getWidth() - 1), + EnumFacing.getFacingFromAxis(direction, axis), EnumFacing.UP, loadingCache, size.getWidth(), size.getHeight(), 1); + + for (int i = 0; i < size.getWidth(); ++i) { + for (int j = 0; j < size.getHeight(); ++j) { + if (patternHelper.translateOffset(i, j, 1).getBlockState().getMaterial() != Material.AIR) { + ++aint[direction.ordinal()]; + } + } + } + } + + AxisDirection axisDirection = AxisDirection.POSITIVE; + for (AxisDirection direction : AxisDirection.values()) { + if (aint[direction.ordinal()] < aint[axisDirection.ordinal()]) { + axisDirection = direction; + } + } + return new PatternHelper(enumfacing.getAxisDirection() == axisDirection ? blockpos : blockpos.offset(size.rightDir, size.getWidth() - 1), + EnumFacing.getFacingFromAxis(axisDirection, axis), EnumFacing.UP, loadingCache, size.getWidth(), size.getHeight(), 1); + } + + @Override + public void neighborChanged(IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, Block blockIn, BlockPos fromPos) { + Axis axis = state.getValue(AXIS); + if (axis == Axis.X || axis == Axis.Z) { + BlockBasic.Size size = new BlockBasic.Size(world, pos, axis); + if (!size.isValid() || size.portalBlockCount < size.width * size.height) { + world.setBlockState(pos, Blocks.AIR.getDefaultState()); + } + } + } + + @Override + public boolean trySpawnPortal(@Nonnull World world, BlockPos pos) { + return trySpawnPortal(world, pos, Axis.X) || trySpawnPortal(world, pos, Axis.Z); + } + + private boolean trySpawnPortal(@Nonnull World world, BlockPos pos, Axis axis) { + BlockBasic.Size size = new BlockBasic.Size(world, pos, axis); + if (size.isValid() && size.portalBlockCount == 0 && !ForgeEventFactory.onTrySpawnPortal(world, pos, size)) { + size.placePortalBlocks(); + return true; + } + return false; + } + } + + public static class NeighborListener { + + public static final NeighborListener instance = new NeighborListener(); + + public NeighborListener() { + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onNeighborNotify(NeighborNotifyEvent e) { + if (e.getState().getBlock() == Blocks.OBSIDIAN) { + World world = e.getWorld(); + Block newBlock = world.getBlockState(e.getPos()).getBlock(); + if (newBlock instanceof BlockFire) { + BlockPortalOverride.instance.trySpawnPortal(world, e.getPos()); + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/block/states/BlockStateBasic.java b/src/main/java/mekanism/common/block/states/BlockStateBasic.java index 4d8f03ab9..8c2111bbf 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateBasic.java +++ b/src/main/java/mekanism/common/block/states/BlockStateBasic.java @@ -78,20 +78,20 @@ public class BlockStateBasic extends ExtendedBlockState { } public enum BasicBlockType implements IStringSerializable { - OSMIUM_BLOCK(BasicBlock.BASIC_BLOCK_1, 0, "OsmiumBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), - BRONZE_BLOCK(BasicBlock.BASIC_BLOCK_1, 1, "BronzeBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), - REFINED_OBSIDIAN(BasicBlock.BASIC_BLOCK_1, 2, "RefinedObsidian", null, false, BlockStateUtils.NO_ROTATION, false, false, true), - COAL_BLOCK(BasicBlock.BASIC_BLOCK_1, 3, "CharcoalBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, false), - REFINED_GLOWSTONE(BasicBlock.BASIC_BLOCK_1, 4, "RefinedGlowstone", null, false, BlockStateUtils.NO_ROTATION, false, false, true), - STEEL_BLOCK(BasicBlock.BASIC_BLOCK_1, 5, "SteelBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + OSMIUM_BLOCK(BasicBlock.BASIC_BLOCK_1, 0, "OsmiumBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), + BRONZE_BLOCK(BasicBlock.BASIC_BLOCK_1, 1, "BronzeBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), + REFINED_OBSIDIAN(BasicBlock.BASIC_BLOCK_1, 2, "RefinedObsidian", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), + COAL_BLOCK(BasicBlock.BASIC_BLOCK_1, 3, "CharcoalBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, false, false, true), + REFINED_GLOWSTONE(BasicBlock.BASIC_BLOCK_1, 4, "RefinedGlowstone", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), + STEEL_BLOCK(BasicBlock.BASIC_BLOCK_1, 5, "SteelBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), BIN(BasicBlock.BASIC_BLOCK_1, 6, "Bin", TileEntityBin::new, true, Plane.HORIZONTAL, true, true, false, true), TELEPORTER_FRAME(BasicBlock.BASIC_BLOCK_1, 7, "TeleporterFrame", null, true, BlockStateUtils.NO_ROTATION, false, false, false), STEEL_CASING(BasicBlock.BASIC_BLOCK_1, 8, "SteelCasing", null, true, BlockStateUtils.NO_ROTATION, false, false, false), DYNAMIC_TANK(BasicBlock.BASIC_BLOCK_1, 9, "DynamicTank", TileEntityDynamicTank::new, true, BlockStateUtils.NO_ROTATION, false, false, false), STRUCTURAL_GLASS(BasicBlock.BASIC_BLOCK_1, 10, "StructuralGlass", TileEntityStructuralGlass::new, true, BlockStateUtils.NO_ROTATION, false, false, false), DYNAMIC_VALVE(BasicBlock.BASIC_BLOCK_1, 11, "DynamicValve", TileEntityDynamicValve::new, true, BlockStateUtils.NO_ROTATION, false, false, false, true), - COPPER_BLOCK(BasicBlock.BASIC_BLOCK_1, 12, "CopperBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), - TIN_BLOCK(BasicBlock.BASIC_BLOCK_1, 13, "TinBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true), + COPPER_BLOCK(BasicBlock.BASIC_BLOCK_1, 12, "CopperBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), + TIN_BLOCK(BasicBlock.BASIC_BLOCK_1, 13, "TinBlock", null, false, BlockStateUtils.NO_ROTATION, false, false, true, false, true), THERMAL_EVAPORATION_CONTROLLER(BasicBlock.BASIC_BLOCK_1, 14, "ThermalEvaporationController", TileEntityThermalEvaporationController::new, true, Plane.HORIZONTAL, true, false, false), THERMAL_EVAPORATION_VALVE(BasicBlock.BASIC_BLOCK_1, 15, "ThermalEvaporationValve", TileEntityThermalEvaporationValve::new, true, BlockStateUtils.NO_ROTATION, false, false, false, true), THERMAL_EVAPORATION_BLOCK(BasicBlock.BASIC_BLOCK_2, 0, "ThermalEvaporationBlock", TileEntityThermalEvaporationBlock::new, true, BlockStateUtils.NO_ROTATION, false, false, false), @@ -116,6 +116,7 @@ public class BlockStateBasic extends ExtendedBlockState { public boolean tiers; public boolean isBeaconBase; public boolean hasRedstoneOutput; + public boolean isFullBlock; BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, boolean activeState, boolean t, boolean beaconBase) { @@ -124,6 +125,11 @@ public class BlockStateBasic extends ExtendedBlockState { BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, boolean activeState, boolean t, boolean beaconBase, boolean hasRedstoneOutput) { + this(block, metadata, s, tileClass, hasDesc, facingAllowed, activeState, t, beaconBase, hasRedstoneOutput, false); + } + + BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, + boolean activeState, boolean t, boolean beaconBase, boolean hasRedstoneOutput, boolean fullBlock) { blockType = block; meta = metadata; name = s; @@ -134,6 +140,7 @@ public class BlockStateBasic extends ExtendedBlockState { tiers = t; isBeaconBase = beaconBase; this.hasRedstoneOutput = hasRedstoneOutput; + isFullBlock = fullBlock; } @Nullable diff --git a/src/main/resources/mekanism_at.cfg b/src/main/resources/mekanism_at.cfg index 5e780a666..e399e88e1 100644 --- a/src/main/resources/mekanism_at.cfg +++ b/src/main/resources/mekanism_at.cfg @@ -28,4 +28,12 @@ public net.minecraft.client.network.NetworkPlayerInfo field_187107_a #playerText public net.minecraft.entity.Entity func_180432_n(Lnet/minecraft/entity/Entity;)V #copyDataFromOld #net.minecraft.client.renderer.BufferBuilder -public net.minecraft.client.renderer.BufferBuilder field_179010_r #isDrawing \ No newline at end of file +public net.minecraft.client.renderer.BufferBuilder field_179010_r #isDrawing + +#net.minecraft.block.BlockPortal$Size +public net.minecraft.block.BlockPortal$Size field_150867_a #world +public net.minecraft.block.BlockPortal$Size field_150861_f #bottomLeft +public net.minecraft.block.BlockPortal$Size field_150862_g #height +public net.minecraft.block.BlockPortal$Size field_150868_h #width +public net.minecraft.block.BlockPortal$Size field_150863_d #leftDir +public net.minecraft.block.BlockPortal$Size field_150866_c #rightDir \ No newline at end of file