Fix sponge bug and improve rift setup system
This commit is contained in:
parent
de53f20420
commit
94cadce276
18 changed files with 129 additions and 65 deletions
|
@ -49,8 +49,6 @@ public class DimDoors {
|
|||
|
||||
@Getter private GatewayGenerator gatewayGenerator;
|
||||
|
||||
public static boolean disableRiftSetup = false; // TODO: Find a better system.
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onPreInitialization(FMLPreInitializationEvent event) {
|
||||
log = event.getModLog();
|
||||
|
@ -88,7 +86,7 @@ public class DimDoors {
|
|||
}
|
||||
|
||||
// TODO: I18n is deprecated, convert to TextComponentTranslation
|
||||
public static void translateAndAdd(String key, List<String> list) {
|
||||
public static void translateAndAdd(String key, List<String> list) { // TODO: move to utils?
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (I18n.canTranslate(key + Integer.toString(i))) {
|
||||
String line = I18n.translateToLocal(key + Integer.toString(i));
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ModelManager {
|
|||
register(getItemFromBlock(ModBlocks.FABRIC), 5, "eternal");
|
||||
|
||||
register(getItemFromBlock(ModBlocks.RIFT));
|
||||
register(getItemFromBlock(ModBlocks.DIMENSIONAL_TRAPDOOR));
|
||||
register(getItemFromBlock(ModBlocks.WOOD_DIMENSIONAL_TRAPDOOR));
|
||||
|
||||
//Item registration
|
||||
register(ModItems.DIMENSIONAL_DOOR);
|
||||
|
|
|
@ -56,7 +56,7 @@ public class CraftingManager {
|
|||
event.getRegistry().register(makeShapedRecipe(new ItemStack(ModItems.WARP_DIMENSIONAL_DOOR, 1),
|
||||
"yxy", 'x', Items.ENDER_PEARL, 'y', Items.OAK_DOOR));
|
||||
|
||||
event.getRegistry().register(makeShapedRecipe(new ItemStack(ModBlocks.DIMENSIONAL_TRAPDOOR, 1),
|
||||
event.getRegistry().register(makeShapedRecipe(new ItemStack(ModBlocks.WOOD_DIMENSIONAL_TRAPDOOR, 1),
|
||||
"y", "x", "y", 'x', Items.ENDER_PEARL, 'y', Blocks.TRAPDOOR));
|
||||
|
||||
event.getRegistry().register(makeShapedRecipe(new ItemStack(ModItems.GOLD_DIMENSIONAL_DOOR, 1),
|
||||
|
|
|
@ -2,17 +2,11 @@ package com.zixiken.dimdoors.shared.blocks;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.VirtualLocation;
|
||||
import com.zixiken.dimdoors.shared.pockets.Pocket;
|
||||
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
|
||||
import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
|
||||
import ddutils.Location;
|
||||
import ddutils.WorldUtils;
|
||||
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -114,12 +108,6 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
|
|||
return rift;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
||||
super.onBlockAdded(worldIn, pos, state);
|
||||
handleRiftPlaced(worldIn, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
if (!hasTileEntity(state)) return;
|
||||
|
|
|
@ -62,12 +62,6 @@ public abstract class BlockDimensionalTrapdoor extends BlockTrapDoor implements
|
|||
return rift;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
||||
super.onBlockAdded(worldIn, pos, state);
|
||||
handleRiftPlaced(worldIn, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||
getRift(world, pos, state).unregister();
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
package com.zixiken.dimdoors.shared.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.VirtualLocation;
|
||||
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
|
||||
import ddutils.Location;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public interface IRiftProvider<T extends TileEntityRift> extends ITileEntityProvider {
|
||||
|
||||
// This returns whether that block is the block containg the rift. If the rift entity does not exist, it must be created
|
||||
public T getRift(World world, BlockPos pos, IBlockState state); // TODO: split this to superinterface IHasRiftEntity?
|
||||
|
||||
public void setupRift(T rift);
|
||||
|
@ -22,20 +20,19 @@ public interface IRiftProvider<T extends TileEntityRift> extends ITileEntityProv
|
|||
@Override
|
||||
public T createNewTileEntity(World world, int meta);
|
||||
|
||||
public default void handleRiftPlaced(World world, BlockPos pos, IBlockState state) {
|
||||
if (hasTileEntity(state) && !DimDoors.disableRiftSetup) {
|
||||
T rift = createNewTileEntity(world, state.getBlock().getMetaFromState(state));
|
||||
// Call only once per structure (on item place)!
|
||||
public default void handleRiftSetup(World world, BlockPos pos, IBlockState state) {
|
||||
T rift = getRift(world, pos, state);
|
||||
|
||||
// Set the rift's virtual position
|
||||
rift.setVirtualLocation(VirtualLocation.fromLocation(new Location(world, pos)));
|
||||
// Set the rift's virtual position
|
||||
rift.setVirtualLocation(VirtualLocation.fromLocation(new Location(world, pos)));
|
||||
|
||||
// Configure the rift to its default functionality
|
||||
setupRift(rift);
|
||||
// Configure the rift to its default functionality
|
||||
setupRift(rift);
|
||||
|
||||
// Set the tile entity and register it
|
||||
world.setTileEntity(pos, rift);
|
||||
rift.markDirty();
|
||||
rift.register();
|
||||
}
|
||||
// Set the tile entity and register it
|
||||
world.setTileEntity(pos, rift);
|
||||
rift.markDirty();
|
||||
rift.register();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class ModBlocks {
|
|||
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 BlockDimensionalTrapdoorWood DIMENSIONAL_TRAPDOOR = new BlockDimensionalTrapdoorWood();
|
||||
public static final BlockDimensionalTrapdoorWood WOOD_DIMENSIONAL_TRAPDOOR = new BlockDimensionalTrapdoorWood();
|
||||
|
||||
// Blocks
|
||||
public static final BlockFabric FABRIC = new BlockFabric();
|
||||
|
@ -34,7 +34,7 @@ public class ModBlocks {
|
|||
UNSTABLE_DIMENSIONAL_DOOR,
|
||||
TRANSIENT_DIMENSIONAL_DOOR,
|
||||
WARP_DIMENSIONAL_DOOR,
|
||||
DIMENSIONAL_TRAPDOOR,
|
||||
WOOD_DIMENSIONAL_TRAPDOOR,
|
||||
FABRIC,
|
||||
RIFT);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.zixiken.dimdoors.shared.items;
|
||||
|
||||
import com.zixiken.dimdoors.shared.blocks.IRiftProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class ItemDimensionalDoor extends ItemDoor {
|
||||
|
||||
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) {
|
||||
EnumActionResult result = super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||
if (result == EnumActionResult.SUCCESS) {
|
||||
IBlockState state = world.getBlockState(pos.offset(facing));
|
||||
((IRiftProvider<?>) state.getBlock()).handleRiftSetup(world, pos.offset(facing), state);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -13,9 +13,9 @@ import net.minecraft.world.World;
|
|||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
|
||||
public class ItemDimDoorGold extends ItemDoor {
|
||||
public class ItemDimensionalDoorGold extends ItemDoor {
|
||||
|
||||
public ItemDimDoorGold() {
|
||||
public ItemDimensionalDoorGold() {
|
||||
super(ModBlocks.GOLD_DIMENSIONAL_DOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalDoorGold.ID);
|
|
@ -6,16 +6,15 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.shared.blocks.BlockDimensionalDoorIron;
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
|
||||
public class ItemDimDoor extends ItemDoor {
|
||||
public class ItemDimensionalDoorIron extends ItemDimensionalDoor {
|
||||
|
||||
public ItemDimDoor() {
|
||||
public ItemDimensionalDoorIron() {
|
||||
super(ModBlocks.DIMENSIONAL_DOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalDoorIron.ID);
|
|
@ -6,16 +6,15 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.shared.blocks.BlockDimensionalDoorPersonal;
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
|
||||
public class ItemDimDoorPersonal extends ItemDoor {
|
||||
public class ItemDimensionalDoorPersonal extends ItemDimensionalDoor {
|
||||
|
||||
public ItemDimDoorPersonal() {
|
||||
public ItemDimensionalDoorPersonal() {
|
||||
super(ModBlocks.PERSONAL_DIMENSIONAL_DOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalDoorPersonal.ID);
|
|
@ -6,16 +6,15 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.shared.blocks.BlockDimensionalDoorUnstable;
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
|
||||
public class ItemDimDoorUnstable extends ItemDoor {
|
||||
public class ItemDimensionalDoorUnstable extends ItemDimensionalDoor {
|
||||
|
||||
public ItemDimDoorUnstable() {
|
||||
public ItemDimensionalDoorUnstable() {
|
||||
super(ModBlocks.UNSTABLE_DIMENSIONAL_DOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalDoorUnstable.ID);
|
|
@ -13,9 +13,9 @@ import net.minecraft.world.World;
|
|||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
|
||||
public class ItemDimDoorWarp extends ItemDoor {
|
||||
public class ItemDimensionalDoorWarp extends ItemDimensionalDoor {
|
||||
|
||||
public ItemDimDoorWarp() {
|
||||
public ItemDimensionalDoorWarp() {
|
||||
super(ModBlocks.WARP_DIMENSIONAL_DOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalDoorWarp.ID);
|
|
@ -0,0 +1,32 @@
|
|||
package com.zixiken.dimdoors.shared.items;
|
||||
|
||||
import com.zixiken.dimdoors.shared.blocks.IRiftProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public abstract class ItemDimensionalTrapdoor extends ItemBlock {
|
||||
|
||||
public <T extends Block & IRiftProvider<?>>ItemDimensionalTrapdoor(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) {
|
||||
EnumActionResult result = super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||
if (result == EnumActionResult.SUCCESS) {
|
||||
IBlockState state = world.getBlockState(pos.offset(facing));
|
||||
((IRiftProvider<?>) state.getBlock()).handleRiftSetup(world, pos.offset(facing), state);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.zixiken.dimdoors.shared.items;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimensionalDoorIron;
|
||||
import com.zixiken.dimdoors.shared.blocks.BlockDimensionalTrapdoorWood;
|
||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||
|
||||
public class ItemDimensionalTrapdoorWood extends ItemDimensionalTrapdoor {
|
||||
|
||||
public ItemDimensionalTrapdoorWood() {
|
||||
super(ModBlocks.WOOD_DIMENSIONAL_TRAPDOOR);
|
||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
||||
setUnlocalizedName(BlockDimensionalTrapdoorWood.ID);
|
||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimensionalTrapdoorWood.ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||
translateAndAdd("info.wood_dimensional_trapdoor", tooltip);
|
||||
}
|
||||
}
|
|
@ -6,11 +6,11 @@ import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
|||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemBlockFabric extends ItemBlock {
|
||||
public class ItemFabric extends ItemBlock {
|
||||
|
||||
private static final String[] subNames = {"_reality", "_ancient", "_altered", "_ancient_altered", "_unraveled", "_eternal"};
|
||||
|
||||
public ItemBlockFabric() {
|
||||
public ItemFabric() {
|
||||
super(ModBlocks.FABRIC);
|
||||
setMaxDamage(0);
|
||||
setHasSubtypes(true);
|
|
@ -13,11 +13,11 @@ public class ModItems {
|
|||
public static final ItemDoorQuartz QUARTZ_DOOR = new ItemDoorQuartz();
|
||||
|
||||
// Dimensional doors
|
||||
public static final ItemDimDoor DIMENSIONAL_DOOR = new ItemDimDoor();
|
||||
public static final ItemDimDoorGold GOLD_DIMENSIONAL_DOOR = new ItemDimDoorGold();
|
||||
public static final ItemDimDoorPersonal PERSONAL_DIMENSIONAL_DOOR = new ItemDimDoorPersonal();
|
||||
public static final ItemDimDoorUnstable UNSTABLE_DIMENSIONAL_DOOR = new ItemDimDoorUnstable();
|
||||
public static final ItemDimDoorWarp WARP_DIMENSIONAL_DOOR = new ItemDimDoorWarp();
|
||||
public static final ItemDimensionalDoorIron DIMENSIONAL_DOOR = new ItemDimensionalDoorIron();
|
||||
public static final ItemDimensionalDoorGold GOLD_DIMENSIONAL_DOOR = new ItemDimensionalDoorGold();
|
||||
public static final ItemDimensionalDoorPersonal PERSONAL_DIMENSIONAL_DOOR = new ItemDimensionalDoorPersonal();
|
||||
public static final ItemDimensionalDoorUnstable UNSTABLE_DIMENSIONAL_DOOR = new ItemDimensionalDoorUnstable();
|
||||
public static final ItemDimensionalDoorWarp WARP_DIMENSIONAL_DOOR = new ItemDimensionalDoorWarp();
|
||||
|
||||
// Fabric
|
||||
public static final ItemWorldThread WORLD_THREAD = new ItemWorldThread();
|
||||
|
@ -27,8 +27,9 @@ public class ModItems {
|
|||
public static final ItemRiftConnectionTool RIFT_CONNECTION_TOOL = new ItemRiftConnectionTool();
|
||||
public static final ItemRiftBlade RIFT_BLADE = new ItemRiftBlade();
|
||||
|
||||
// This needs to exist to be used in ModelManager.java before items are registered (preinitialization)
|
||||
public static final ItemBlockFabric FABRIC = new ItemBlockFabric();
|
||||
// ItemBlocks
|
||||
public static final ItemFabric FABRIC = new ItemFabric();
|
||||
public static final ItemDimensionalTrapdoorWood WOOD_DIMENSIONAL_TRAPDOOR = new ItemDimensionalTrapdoorWood();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||
|
@ -48,7 +49,7 @@ public class ModItems {
|
|||
// ItemBlocks
|
||||
event.getRegistry().registerAll(
|
||||
FABRIC,
|
||||
new ItemBlock(ModBlocks.DIMENSIONAL_TRAPDOOR).setRegistryName(ModBlocks.DIMENSIONAL_TRAPDOOR.getRegistryName()),
|
||||
WOOD_DIMENSIONAL_TRAPDOOR,
|
||||
new ItemBlock(ModBlocks.RIFT).setRegistryName(ModBlocks.RIFT.getRegistryName()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,7 @@ public class PocketTemplate {
|
|||
DimDoors.log.info("Placing new pocket using schematic " + schematic.schematicName + " at x = " + xBase + ", z = " + zBase);
|
||||
|
||||
WorldServer world = DimDoors.proxy.getWorldServer(dimID);
|
||||
DimDoors.disableRiftSetup = true;
|
||||
Schematic.place(schematic, world, xBase, yBase, zBase);
|
||||
DimDoors.disableRiftSetup = false;
|
||||
|
||||
// Set pocket riftLocations
|
||||
pocket.riftLocations = new ArrayList<>();
|
||||
|
|
Loading…
Reference in a new issue