Make Refined Obsidian usable for Nether Portals (#5479)

* Make Refined Obsidian usable for Nether Portals

* Fix spacing changes

* Remove some duplicate code

* Fix a small param passing error
This commit is contained in:
ToMe25 authored and Richard Freimer committed 2019-05-20 10:07:52 -04:00
1 parent 2809912037
commit d6bca945fe
4 files changed
+208 -10

No files matched your search

@@ -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);
}
/**
@@ -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<BlockPos, BlockWorldState> 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());
}
}
}
}
}
@@ -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<TileEntity> tileClass, boolean hasDesc, Predicate<EnumFacing> 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<TileEntity> tileClass, boolean hasDesc, Predicate<EnumFacing> 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<TileEntity> tileClass, boolean hasDesc, Predicate<EnumFacing> 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