Implement placing doors on rifts
This commit is contained in:
parent
464f516a40
commit
be184579e1
17 changed files with 98 additions and 14 deletions
|
@ -2,6 +2,7 @@ package org.dimdev.dimdoors.shared.blocks;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.BlockFaceShape;
|
||||
import org.dimdev.dimdoors.shared.rifts.RiftRegistry;
|
||||
import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
||||
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
|
@ -87,6 +88,23 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
|
|||
return state.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World world, BlockPos pos) {
|
||||
if (canBePlacedOnRift()) {
|
||||
if (pos.getY() >= world.getHeight() - 1) {
|
||||
return false;
|
||||
} else {
|
||||
IBlockState state = world.getBlockState(pos.down());
|
||||
return (state.isSideSolid(world, pos, EnumFacing.UP)
|
||||
|| state.getBlockFaceShape(world, pos.down(), EnumFacing.UP) == BlockFaceShape.SOLID)
|
||||
&& (world.getBlockState(pos).getBlock().isReplaceable(world, pos) || world.getBlockState(pos).getBlock().equals(ModBlocks.RIFT))
|
||||
&& world.getBlockState(pos).getBlock().isReplaceable(world, pos.up());
|
||||
}
|
||||
} else {
|
||||
return super.canPlaceBlockAt(world, pos.down());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
||||
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? Items.AIR : getItem();
|
||||
|
@ -131,4 +149,6 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
|
|||
}
|
||||
|
||||
public abstract Item getItem();
|
||||
|
||||
public abstract boolean canBePlacedOnRift();
|
||||
}
|
||||
|
|
|
@ -35,4 +35,9 @@ public class BlockDimensionalDoorGold extends BlockDimensionalDoor {
|
|||
public void setupRift(TileEntityEntranceRift rift) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOnRift() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,4 +39,9 @@ public class BlockDimensionalDoorIron extends BlockDimensionalDoor {
|
|||
NewPublicDestination destination = NewPublicDestination.builder().build();
|
||||
rift.setSingleDestination(destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOnRift() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,4 +43,9 @@ public class BlockDimensionalDoorPersonal extends BlockDimensionalDoor {
|
|||
}
|
||||
rift.setChaosWeight(0); // TODO: generated schematic exits too
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOnRift() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,4 +32,9 @@ public class BlockDimensionalDoorTransient extends BlockDimensionalDoor { // TOD
|
|||
public void setupRift(TileEntityEntranceRift rift) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOnRift() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,9 @@ public class BlockDimensionalDoorUnstable extends BlockDimensionalDoor {
|
|||
public void setupRift(TileEntityEntranceRift rift) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOnRift() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockDimensionalDoorWarp extends BlockDimensionalDoor {
|
||||
public class BlockDimensionalDoorWood extends BlockDimensionalDoor {
|
||||
|
||||
public static final String ID = "warp_dimensional_door";
|
||||
|
||||
public BlockDimensionalDoorWarp() {
|
||||
public BlockDimensionalDoorWood() {
|
||||
super(Material.WOOD);
|
||||
setHardness(1.0F);
|
||||
setUnlocalizedName(ID);
|
||||
|
@ -36,4 +36,9 @@ public class BlockDimensionalDoorWarp extends BlockDimensionalDoor {
|
|||
public void setupRift(TileEntityEntranceRift rift) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOnRift() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -72,4 +72,6 @@ public abstract class BlockDimensionalTrapdoor extends BlockTrapDoor implements
|
|||
public TileEntityEntranceRift getRift(World world, BlockPos pos, IBlockState state) {
|
||||
return (TileEntityEntranceRift) world.getTileEntity(pos);
|
||||
}
|
||||
|
||||
public abstract boolean canBePlacedOnRift(); // TODO
|
||||
}
|
||||
|
|
|
@ -34,4 +34,8 @@ public class BlockDimensionalTrapdoorWood extends BlockDimensionalTrapdoor {
|
|||
public void setupRift(TileEntityEntranceRift rift) {
|
||||
rift.setSingleDestination(new EscapeDestination());
|
||||
}
|
||||
|
||||
@Override public boolean canBePlacedOnRift() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import net.minecraft.world.World;
|
|||
|
||||
public class BlockFabric extends Block {
|
||||
|
||||
public static final Material FIREPROOF_FABRIC = new Material(MapColor.BLACK);
|
||||
public static final Material FABRIC = new Material(MapColor.BLACK);
|
||||
public static final String ID = "fabric";
|
||||
public static final PropertyEnum<EnumType> TYPE = PropertyEnum.create("type", BlockFabric.EnumType.class);
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class BlockFabric extends Block {
|
|||
}
|
||||
|
||||
public BlockFabric() {
|
||||
super(FIREPROOF_FABRIC);
|
||||
super(FABRIC);
|
||||
setRegistryName(new ResourceLocation(DimDoors.MODID, ID));
|
||||
setUnlocalizedName(ID);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
|
|
|
@ -16,7 +16,7 @@ public final class ModBlocks {
|
|||
public static final BlockDimensionalDoorPersonal PERSONAL_DIMENSIONAL_DOOR = new BlockDimensionalDoorPersonal();
|
||||
public static final BlockDimensionalDoorUnstable UNSTABLE_DIMENSIONAL_DOOR = new BlockDimensionalDoorUnstable();
|
||||
public static final BlockDimensionalDoorTransient TRANSIENT_DIMENSIONAL_DOOR = new BlockDimensionalDoorTransient();
|
||||
public static final BlockDimensionalDoorWarp WARP_DIMENSIONAL_DOOR = new BlockDimensionalDoorWarp();
|
||||
public static final BlockDimensionalDoorWood WARP_DIMENSIONAL_DOOR = new BlockDimensionalDoorWood();
|
||||
public static final BlockDimensionalTrapdoorWood WOOD_DIMENSIONAL_TRAPDOOR = new BlockDimensionalTrapdoorWood();
|
||||
|
||||
// Blocks
|
||||
|
|
|
@ -10,24 +10,43 @@ import net.minecraft.util.EnumFacing;
|
|||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
|
||||
import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
||||
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
|
||||
public abstract class ItemDimensionalDoor extends ItemDoor {
|
||||
|
||||
public <T extends Block & IRiftProvider<?>>ItemDimensionalDoor(T block) {
|
||||
public <T extends Block & IRiftProvider<?>> ItemDimensionalDoor(T block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
// TODO: endermen/block placers should set up blocks too, but this method doesn't get called when they place the block
|
||||
@Override
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
boolean replaceable = world.getBlockState(pos).getBlock().isReplaceable(world, pos); // Check this before calling super, since that changes the block
|
||||
if (world.isRemote) return EnumActionResult.FAIL;
|
||||
boolean replaceable = world.getBlockState(pos).getBlock().isReplaceable(world, pos);
|
||||
|
||||
// Store the rift entity if there's a rift block there that may be broken
|
||||
TileEntityFloatingRift rift = null;
|
||||
if (world.getBlockState(replaceable ? pos : pos.offset(facing)).getBlock().equals(ModBlocks.RIFT)) {
|
||||
rift = (TileEntityFloatingRift) world.getTileEntity(replaceable ? pos : pos.offset(facing));
|
||||
rift.setUnregisterDisabled(true);
|
||||
}
|
||||
|
||||
EnumActionResult result = super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||
if (!replaceable) pos = pos.offset(facing);
|
||||
if (result == EnumActionResult.SUCCESS) {
|
||||
if (!replaceable) pos = pos.offset(facing);
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() instanceof IRiftProvider<?>) { // In case the door is placed on glass/leaves
|
||||
if (rift == null) {
|
||||
((IRiftProvider<?>) state.getBlock()).handleRiftSetup(world, pos, state);
|
||||
} else {
|
||||
// Copy from the old rift
|
||||
TileEntityEntranceRift newRift = (TileEntityEntranceRift) world.getTileEntity(pos);
|
||||
newRift.copyFrom(rift);
|
||||
newRift.updateAvailableLinks();
|
||||
}
|
||||
} else if (rift != null) {
|
||||
rift.setUnregisterDisabled(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.dimdev.dimdoors.shared.items;
|
|||
import java.util.List;
|
||||
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockDimensionalDoorWarp;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockDimensionalDoorWood;
|
||||
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
|
||||
import org.dimdev.ddutils.I18nUtils;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
|
@ -18,8 +18,8 @@ public class ItemDimensionalDoorWarp extends ItemDimensionalDoor {
|
|||
public ItemDimensionalDoorWarp() {
|
||||
super(ModBlocks.WARP_DIMENSIONAL_DOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalDoorWarp.ID);
|
||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimensionalDoorWarp.ID));
|
||||
setUnlocalizedName(BlockDimensionalDoorWood.ID);
|
||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimensionalDoorWood.ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ItemRiftSignature extends Item {
|
|||
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift1 = (TileEntityRift) world.getTileEntity(pos);
|
||||
rift1.setSingleDestination(new GlobalDestination(source.getLocation()));
|
||||
rift1.setRotation(source.getYaw(), 0);
|
||||
rift1.setRotation(player.rotationYaw, 0);
|
||||
rift1.register();
|
||||
|
||||
// Place a rift at the source point
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla
|
|||
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift1 = (TileEntityRift) world.getTileEntity(pos);
|
||||
rift1.setSingleDestination(new GlobalDestination(source.getLocation()));
|
||||
rift1.setRotation(source.getYaw(), 0);
|
||||
rift1.setRotation(player.rotationYaw, 0);
|
||||
rift1.register();
|
||||
|
||||
// Place a rift at the source point
|
||||
|
|
|
@ -59,6 +59,7 @@ import java.util.*;
|
|||
preserveRotation = oldRift.preserveRotation;
|
||||
yaw = oldRift.yaw;
|
||||
pitch = oldRift.pitch;
|
||||
chaosWeight = oldRift.chaosWeight;
|
||||
if (oldRift.isFloating() != isFloating()) updateAvailableLinks();
|
||||
|
||||
markDirty();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.dimdev.dimdoors.shared.tileentities;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.ddutils.nbt.SavedToNBT;
|
||||
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
|
||||
|
@ -30,6 +31,8 @@ import net.minecraft.util.math.AxisAlignedBB;
|
|||
@SavedToNBT public int spawnedEndermenID = 0;
|
||||
@SavedToNBT public float growth = 0;
|
||||
|
||||
@Setter private boolean unregisterDisabled = false;
|
||||
|
||||
public TileEntityFloatingRift() {
|
||||
updateTimer = random.nextInt(UPDATE_PERIOD);
|
||||
}
|
||||
|
@ -112,4 +115,9 @@ import net.minecraft.util.math.AxisAlignedBB;
|
|||
public boolean isFloating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister() {
|
||||
if (!unregisterDisabled) super.unregister();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue