Improvements
- Remove some unused code - Better logging - Bug fixes - Unify pocket placing and gateway placing code
This commit is contained in:
parent
cc952a642f
commit
915bc41a08
24 changed files with 93 additions and 323 deletions
|
@ -19,23 +19,27 @@ import net.minecraftforge.fml.common.event.*;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mod(modid = DimDoors.MODID, name = "Dimensional Doors", version = DimDoors.VERSION, dependencies = "required-after:forge@[14.23.0.2517,)")
|
@Mod(modid = DimDoors.MODID, name = "Dimensional Doors",
|
||||||
|
version = DimDoors.VERSION,
|
||||||
|
dependencies = "required-after:forge@[14.23.0.2517,)")
|
||||||
public class DimDoors {
|
public class DimDoors {
|
||||||
|
|
||||||
public static final String MODID = "dimdoors";
|
public static final String MODID = "dimdoors";
|
||||||
public static final String VERSION = "${version}";
|
public static final String VERSION = "${version}";
|
||||||
@Getter private GatewayGenerator gatewayGenerator;
|
|
||||||
|
@Mod.Instance(DimDoors.MODID)
|
||||||
|
public static DimDoors instance;
|
||||||
|
|
||||||
|
public static Logger log; // TODO: make non-static?
|
||||||
|
|
||||||
@SidedProxy(clientSide = "com.zixiken.dimdoors.client.DDProxyClient",
|
@SidedProxy(clientSide = "com.zixiken.dimdoors.client.DDProxyClient",
|
||||||
serverSide = "com.zixiken.dimdoors.server.DDProxyServer")
|
serverSide = "com.zixiken.dimdoors.server.DDProxyServer")
|
||||||
public static DDProxyCommon proxy;
|
public static DDProxyCommon proxy;
|
||||||
|
|
||||||
@Mod.Instance(DimDoors.MODID)
|
|
||||||
public static DimDoors instance;
|
|
||||||
|
|
||||||
public static final CreativeTabs DIM_DOORS_CREATIVE_TAB = new CreativeTabs("dimensional_doors_creative_tab") {
|
public static final CreativeTabs DIM_DOORS_CREATIVE_TAB = new CreativeTabs("dimensional_doors_creative_tab") {
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
|
@ -44,9 +48,13 @@ public class DimDoors {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Getter private GatewayGenerator gatewayGenerator;
|
||||||
|
|
||||||
|
public static boolean disableRiftSetup = false; // TODO: Find a better system.
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void onPreInitialization(FMLPreInitializationEvent event) {
|
public void onPreInitialization(FMLPreInitializationEvent event) {
|
||||||
|
log = event.getModLog();
|
||||||
proxy.onPreInitialization(event);
|
proxy.onPreInitialization(event);
|
||||||
DDConfig.loadConfig(event);
|
DDConfig.loadConfig(event);
|
||||||
}
|
}
|
||||||
|
@ -80,30 +88,6 @@ public class DimDoors {
|
||||||
player.sendMessage(new TextComponentString("[DimDoors] " + text));
|
player.sendMessage(new TextComponentString("[DimDoors] " + text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(String text) {
|
|
||||||
warn(null, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void warn(Class<?> classFiredFrom, String text) {
|
|
||||||
if(classFiredFrom != null) {
|
|
||||||
FMLLog.log.warn("[DimDoors] " + text + " (" + classFiredFrom + " )", 0);
|
|
||||||
} else {
|
|
||||||
FMLLog.log.warn("[DimDoors] " + text, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void log(String text) {
|
|
||||||
log(null, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void log(Class<?> classFiredFrom, String text) {
|
|
||||||
if(classFiredFrom != null) {
|
|
||||||
FMLLog.log.info("[DimDoors] " + text + " (" + classFiredFrom + " )", 0);
|
|
||||||
} else {
|
|
||||||
FMLLog.log.info("[DimDoors] " + text, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: I18n is deprecated, convert to TextComponentTranslation
|
// 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) {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class DDConfig {
|
||||||
config.addCustomCategoryComment("pocket_dimension", "The following values determine the maximum sizes of different kinds of pockets. These values will only influence new worlds.");
|
config.addCustomCategoryComment("pocket_dimension", "The following values determine the maximum sizes of different kinds of pockets. These values will only influence new worlds.");
|
||||||
pocketGridSize = setConfigIntWithMaxAndMin(config, "pocket_dimension", "pocketGridSize", pocketGridSize,
|
pocketGridSize = setConfigIntWithMaxAndMin(config, "pocket_dimension", "pocketGridSize", pocketGridSize,
|
||||||
"Sets how many chunks apart all pockets in pocket dimensions should be placed. [min: 4, max: 32, default: 32]", 4, 32);
|
"Sets how many chunks apart all pockets in pocket dimensions should be placed. [min: 4, max: 32, default: 32]", 4, 32);
|
||||||
DimDoors.log(DDConfig.class, "pocketGridSize was set to " + pocketGridSize);
|
DimDoors.log.info("pocketGridSize was set to " + pocketGridSize);
|
||||||
|
|
||||||
maxPocketSize = setConfigIntWithMaxAndMin(config, "pocket_dimension", "maxPocketSize", maxPocketSize,
|
maxPocketSize = setConfigIntWithMaxAndMin(config, "pocket_dimension", "maxPocketSize", maxPocketSize,
|
||||||
"Sets how deep and wide any pocket can be. [min: 0, max: pocketGridSize/2, default: 4]", 0, (int) ((double) pocketGridSize / 2 - 0.5));
|
"Sets how deep and wide any pocket can be. [min: 0, max: pocketGridSize/2, default: 4]", 0, (int) ((double) pocketGridSize / 2 - 0.5));
|
||||||
|
|
|
@ -19,7 +19,7 @@ public abstract class DDProxyCommon implements IDDProxy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPreInitialization(FMLPreInitializationEvent event) {
|
public void onPreInitialization(FMLPreInitializationEvent event) {
|
||||||
MinecraftForge.EVENT_BUS.register(new DDEventHandler());
|
MinecraftForge.EVENT_BUS.register(EventHandler.class);
|
||||||
MinecraftForge.EVENT_BUS.register(ModBlocks.class);
|
MinecraftForge.EVENT_BUS.register(ModBlocks.class);
|
||||||
MinecraftForge.EVENT_BUS.register(ModItems.class);
|
MinecraftForge.EVENT_BUS.register(ModItems.class);
|
||||||
MinecraftForge.EVENT_BUS.register(CraftingManager.class); // TODO: ModRecipes?
|
MinecraftForge.EVENT_BUS.register(CraftingManager.class); // TODO: ModRecipes?
|
||||||
|
|
|
@ -12,10 +12,10 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
public class DDEventHandler {
|
public class EventHandler {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
|
public static void onPlayerJoinWorld(EntityJoinWorldEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if(entity instanceof EntityPlayer && !entity.world.isRemote) { // check that it's a player first to avoid calling String.contains for every entity
|
if(entity instanceof EntityPlayer && !entity.world.isRemote) { // check that it's a player first to avoid calling String.contains for every entity
|
||||||
if (!DDConfig.HAVE_CONFIG_DEFAULTS_BEEN_CHECKED_FOR_CORRECTNESS && !DimDoors.VERSION.contains("a")) { // default values were not checked in non-alpha version
|
if (!DDConfig.HAVE_CONFIG_DEFAULTS_BEEN_CHECKED_FOR_CORRECTNESS && !DimDoors.VERSION.contains("a")) { // default values were not checked in non-alpha version
|
||||||
|
@ -26,7 +26,7 @@ public class DDEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onLivingFall(LivingFallEvent event) {
|
public static void onLivingFall(LivingFallEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity.dimension == DimDoorDimensions.LIMBO.getId()) {
|
if (entity.dimension == DimDoorDimensions.LIMBO.getId()) {
|
||||||
event.setCanceled(true); // no fall damage in limbo
|
event.setCanceled(true); // no fall damage in limbo
|
||||||
|
@ -34,7 +34,7 @@ public class DDEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
|
public static void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity instanceof EntityPlayerMP) {
|
if (entity instanceof EntityPlayerMP) {
|
||||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
EntityPlayerMP player = (EntityPlayerMP) entity;
|
|
@ -69,12 +69,12 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
|
||||||
String jsonString = IOUtils.toString(file.toURI(), StandardCharsets.UTF_8);
|
String jsonString = IOUtils.toString(file.toURI(), StandardCharsets.UTF_8);
|
||||||
templates.addAll(loadTemplatesFromJson(jsonString));
|
templates.addAll(loadTemplatesFromJson(jsonString));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
DimDoors.warn("Error reading file " + file.toURI() + ". The following exception occured: ");
|
DimDoors.log.error("Error reading file " + file.toURI() + ". The following exception occured: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constructNameMap();
|
constructNameMap();
|
||||||
|
|
||||||
DimDoors.log("Loaded " + templates.size() + " templates.");
|
DimDoors.log.info("Loaded " + templates.size() + " templates.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
|
private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
|
||||||
|
@ -84,11 +84,11 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
JsonElement jsonElement = parser.parse(jsonString);
|
JsonElement jsonElement = parser.parse(jsonString);
|
||||||
JsonObject jsonTemplate = jsonElement.getAsJsonObject();
|
JsonObject jsonTemplate = jsonElement.getAsJsonObject();
|
||||||
//DimDoors.log(SchematicHandler.class, "Checkpoint 1 reached");
|
//DimDoors.log.info("Checkpoint 1 reached");
|
||||||
|
|
||||||
//Generate and get templates (without a schematic) of all variations that are valid for the current "maxPocketSize"
|
//Generate and get templates (without a schematic) of all variations that are valid for the current "maxPocketSize"
|
||||||
List<PocketTemplate> validTemplates = getAllValidVariations(jsonTemplate);
|
List<PocketTemplate> validTemplates = getAllValidVariations(jsonTemplate);
|
||||||
//DimDoors.log(SchematicHandler.class, "Checkpoint 4 reached; " + validTemplates.size() + " templates were loaded");
|
//DimDoors.log.info("Checkpoint 4 reached; " + validTemplates.size() + " templates were loaded");
|
||||||
|
|
||||||
String subDirectory = jsonTemplate.get("group").getAsString(); //get the subfolder in which the schematics are stored
|
String subDirectory = jsonTemplate.get("group").getAsString(); //get the subfolder in which the schematics are stored
|
||||||
|
|
||||||
|
@ -115,17 +115,17 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
|
||||||
schematicDataStream = new DataInputStream(new FileInputStream(schematicFile));
|
schematicDataStream = new DataInputStream(new FileInputStream(schematicFile));
|
||||||
streamOpened = true;
|
streamOpened = true;
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schem did not load correctly from config folder.", ex);
|
DimDoors.log.error("Schematic file " + template.getName() + ".schem did not load correctly from config folder.", ex);
|
||||||
}
|
}
|
||||||
} else if (oldVersionSchematicFile.exists()) {
|
} else if (oldVersionSchematicFile.exists()) {
|
||||||
try {
|
try {
|
||||||
schematicDataStream = new DataInputStream(new FileInputStream(oldVersionSchematicFile));
|
schematicDataStream = new DataInputStream(new FileInputStream(oldVersionSchematicFile));
|
||||||
streamOpened = true;
|
streamOpened = true;
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex);
|
DimDoors.log.error("Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DimDoors.warn(SchematicHandler.class, "Schematic '" + template.getName() + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
|
DimDoors.log.warn("Schematic '" + template.getName() + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound schematicNBT;
|
NBTTagCompound schematicNBT;
|
||||||
|
@ -153,9 +153,10 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
|
||||||
if (schematic != null
|
if (schematic != null
|
||||||
&& (schematic.getWidth() > (template.getSize() + 1) * 16 || schematic.getLength() > (template.getSize() + 1) * 16)) {
|
&& (schematic.getWidth() > (template.getSize() + 1) * 16 || schematic.getLength() > (template.getSize() + 1) * 16)) {
|
||||||
schematic = null;
|
schematic = null;
|
||||||
DimDoors.log(SchematicHandler.class, "Schematic " + template.getName() + " was bigger than specified in its json file and therefore wasn't loaded");
|
DimDoors.log.warn("Schematic " + template.getName() + " was bigger than specified in its json file and therefore wasn't loaded");
|
||||||
}
|
}
|
||||||
template.setSchematic(schematic);
|
template.setSchematic(schematic);
|
||||||
|
// TODO: delete from validTemplates if schematic is null
|
||||||
}
|
}
|
||||||
return validTemplates;
|
return validTemplates;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +275,7 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (weightedTemplates.size() == 0) {
|
if (weightedTemplates.size() == 0) {
|
||||||
DimDoors.warn("getRandomTemplate failed, no templates matching those criteria were found.");
|
DimDoors.log.warn("getRandomTemplate failed, no templates matching those criteria were found.");
|
||||||
return null; // TODO: switch to exception system
|
return null; // TODO: switch to exception system
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.VirtualLocation;
|
import com.zixiken.dimdoors.shared.VirtualLocation;
|
||||||
import com.zixiken.dimdoors.shared.pockets.Pocket;
|
import com.zixiken.dimdoors.shared.pockets.Pocket;
|
||||||
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
|
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
|
||||||
import com.zixiken.dimdoors.shared.pockets.PocketTemplate;
|
|
||||||
import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
|
import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
|
||||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
|
||||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
||||||
|
@ -122,7 +121,7 @@ public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityP
|
||||||
@Override
|
@Override
|
||||||
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
||||||
super.onBlockAdded(worldIn, pos, state);
|
super.onBlockAdded(worldIn, pos, state);
|
||||||
if (hasTileEntity(state) && !PocketTemplate.schematicBeingPlaced) { // TODO: better check for schematicBeingPlaced (support other plugins such as WorldEdit, support doors being placed while schematics are being placed)
|
if (hasTileEntity(state) && !DimDoors.disableRiftSetup) { // TODO: better check for disableRiftSetup (support other plugins such as WorldEdit, support doors being placed while schematics are being placed)
|
||||||
TileEntityVerticalEntranceRift rift = createNewTileEntity(worldIn, getMetaFromState(state));
|
TileEntityVerticalEntranceRift rift = createNewTileEntity(worldIn, getMetaFromState(state));
|
||||||
|
|
||||||
// Set the virtual location based on where the door was placed
|
// Set the virtual location based on where the door was placed
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class CommandDimTeleport extends CommandBase { // TODO: localization
|
||||||
if (sender instanceof Entity) {
|
if (sender instanceof Entity) {
|
||||||
TeleportUtils.teleport((Entity) sender, new Location(dimension, new BlockPos(x, y, z)), yaw, pitch);
|
TeleportUtils.teleport((Entity) sender, new Location(dimension, new BlockPos(x, y, z)), yaw, pitch);
|
||||||
} else {
|
} else {
|
||||||
DimDoors.log("Not executing command /" + getName() + " because it wasn't sent by a player.");
|
DimDoors.log.info("Not executing command /" + getName() + " because it wasn't sent by a player.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class PocketCommand extends CommandBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DimDoors.log("Not executing command /" + getName() + " because it wasn't sent by a player.");
|
DimDoors.log.info("Not executing command /" + getName() + " because it wasn't sent by a player.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class RenderMonolith extends RenderLiving<EntityMonolith> {
|
||||||
|
|
||||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
DimDoors.log.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
|
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||||
|
|
|
@ -4,10 +4,8 @@ import java.util.List;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorIron;
|
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorIron;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.ItemDoor;
|
import net.minecraft.item.ItemDoor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -15,10 +13,10 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||||
|
|
||||||
public class ItemDimDoor extends ItemDoorBase {
|
public class ItemDimDoor extends ItemDoor {
|
||||||
|
|
||||||
public ItemDimDoor() {
|
public ItemDimDoor() {
|
||||||
super(ModBlocks.DIMENSIONAL_DOOR, (ItemDoor) Items.IRON_DOOR);
|
super(ModBlocks.DIMENSIONAL_DOOR);
|
||||||
setUnlocalizedName(BlockDimDoorIron.ID);
|
setUnlocalizedName(BlockDimDoorIron.ID);
|
||||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorIron.ID));
|
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorIron.ID));
|
||||||
}
|
}
|
||||||
|
@ -27,9 +25,4 @@ public class ItemDimDoor extends ItemDoorBase {
|
||||||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||||
translateAndAdd("info.dimensional_door", tooltip);
|
translateAndAdd("info.dimensional_door", tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockDimDoorBase getDoorBlock() {
|
|
||||||
return ModBlocks.DIMENSIONAL_DOOR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package com.zixiken.dimdoors.shared.items;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorGold;
|
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorGold;
|
||||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
|
import net.minecraft.item.ItemDoor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||||
|
|
||||||
public class ItemDimDoorGold extends ItemDoorBase {
|
public class ItemDimDoorGold extends ItemDoor {
|
||||||
|
|
||||||
public ItemDimDoorGold() {
|
public ItemDimDoorGold() {
|
||||||
super(ModBlocks.GOLD_DIMENSIONAL_DOOR, ModItems.GOLD_DOOR);
|
super(ModBlocks.GOLD_DIMENSIONAL_DOOR);
|
||||||
setUnlocalizedName(BlockDimDoorGold.ID);
|
setUnlocalizedName(BlockDimDoorGold.ID);
|
||||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorGold.ID));
|
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorGold.ID));
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,4 @@ public class ItemDimDoorGold extends ItemDoorBase {
|
||||||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||||
translateAndAdd("info.gold_dimensional_door", tooltip);
|
translateAndAdd("info.gold_dimensional_door", tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockDimDoorBase getDoorBlock() {
|
|
||||||
return ModBlocks.GOLD_DIMENSIONAL_DOOR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package com.zixiken.dimdoors.shared.items;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorPersonal;
|
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorPersonal;
|
||||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
|
import net.minecraft.item.ItemDoor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||||
|
|
||||||
public class ItemDimDoorPersonal extends ItemDoorBase {
|
public class ItemDimDoorPersonal extends ItemDoor {
|
||||||
|
|
||||||
public ItemDimDoorPersonal() {
|
public ItemDimDoorPersonal() {
|
||||||
super(ModBlocks.PERSONAL_DIMENSIONAL_DOOR, ModItems.QUARTZ_DOOR);
|
super(ModBlocks.PERSONAL_DIMENSIONAL_DOOR);
|
||||||
setUnlocalizedName(BlockDimDoorPersonal.ID);
|
setUnlocalizedName(BlockDimDoorPersonal.ID);
|
||||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorPersonal.ID));
|
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorPersonal.ID));
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,4 @@ public class ItemDimDoorPersonal extends ItemDoorBase {
|
||||||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||||
translateAndAdd("info.quartz_dimensional_door", tooltip);
|
translateAndAdd("info.quartz_dimensional_door", tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockDimDoorBase getDoorBlock() {
|
|
||||||
return ModBlocks.PERSONAL_DIMENSIONAL_DOOR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package com.zixiken.dimdoors.shared.items;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorUnstable;
|
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorUnstable;
|
||||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
|
import net.minecraft.item.ItemDoor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||||
|
|
||||||
public class ItemDimDoorUnstable extends ItemDoorBase {
|
public class ItemDimDoorUnstable extends ItemDoor {
|
||||||
|
|
||||||
public ItemDimDoorUnstable() {
|
public ItemDimDoorUnstable() {
|
||||||
super(ModBlocks.UNSTABLE_DIMENSIONAL_DOOR, null);
|
super(ModBlocks.UNSTABLE_DIMENSIONAL_DOOR);
|
||||||
setUnlocalizedName(BlockDimDoorUnstable.ID);
|
setUnlocalizedName(BlockDimDoorUnstable.ID);
|
||||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorUnstable.ID));
|
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorUnstable.ID));
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,4 @@ public class ItemDimDoorUnstable extends ItemDoorBase {
|
||||||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||||
translateAndAdd("info.unstable_dimensional_door", tooltip);
|
translateAndAdd("info.unstable_dimensional_door", tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockDimDoorBase getDoorBlock() {
|
|
||||||
return ModBlocks.UNSTABLE_DIMENSIONAL_DOOR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,9 @@ package com.zixiken.dimdoors.shared.items;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorWarp;
|
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorWarp;
|
||||||
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.ItemDoor;
|
import net.minecraft.item.ItemDoor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -15,10 +13,10 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
|
||||||
|
|
||||||
public class ItemDimDoorWarp extends ItemDoorBase {
|
public class ItemDimDoorWarp extends ItemDoor {
|
||||||
|
|
||||||
public ItemDimDoorWarp() {
|
public ItemDimDoorWarp() {
|
||||||
super(ModBlocks.WARP_DIMENSIONAL_DOOR, (ItemDoor) Items.OAK_DOOR);
|
super(ModBlocks.WARP_DIMENSIONAL_DOOR);
|
||||||
setUnlocalizedName(BlockDimDoorWarp.ID);
|
setUnlocalizedName(BlockDimDoorWarp.ID);
|
||||||
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorWarp.ID));
|
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorWarp.ID));
|
||||||
}
|
}
|
||||||
|
@ -27,9 +25,4 @@ public class ItemDimDoorWarp extends ItemDoorBase {
|
||||||
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||||
translateAndAdd("info.warp_dimensional_door", tooltip);
|
translateAndAdd("info.warp_dimensional_door", tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockDimDoorBase getDoorBlock() {
|
|
||||||
return ModBlocks.WARP_DIMENSIONAL_DOOR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,138 +0,0 @@
|
||||||
package com.zixiken.dimdoors.shared.items;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
import com.zixiken.dimdoors.shared.RayTraceHelper;
|
|
||||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
|
||||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemDoor;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.*;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.block.SoundType;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
|
|
||||||
public abstract class ItemDoorBase extends ItemDoor {
|
|
||||||
|
|
||||||
// Maps non-dimensional door items to their corresponding dimensional door item
|
|
||||||
// Also maps dimensional door items to themselves for simplicity
|
|
||||||
private static HashMap<ItemDoor, ItemDoorBase> doorItemMapping = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* door represents the non-dimensional door this item is associated with.
|
|
||||||
* Leave null for none.
|
|
||||||
*
|
|
||||||
* @param vanillaDoor
|
|
||||||
*/
|
|
||||||
public ItemDoorBase(Block block, ItemDoor vanillaDoor) {
|
|
||||||
super(block);
|
|
||||||
setMaxStackSize(64);
|
|
||||||
setCreativeTab(DimDoors.DIM_DOORS_CREATIVE_TAB);
|
|
||||||
|
|
||||||
doorItemMapping.put(this, this); //@todo Why?
|
|
||||||
if (vanillaDoor != null) {
|
|
||||||
doorItemMapping.put(vanillaDoor, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overridden in subclasses to specify which door block that door item will
|
|
||||||
* place
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract BlockDimDoorBase getDoorBlock();
|
|
||||||
|
|
||||||
//onItemUse gets fired before onItemRightClick and if it returns "success", onItemRightClick gets skipped.
|
|
||||||
@Override
|
|
||||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
|
|
||||||
ItemStack stack = playerIn.getHeldItem(handIn);
|
|
||||||
|
|
||||||
if (worldIn.isRemote) {
|
|
||||||
return new ActionResult<>(EnumActionResult.FAIL, stack);
|
|
||||||
}
|
|
||||||
RayTraceResult hit = rayTrace(worldIn, playerIn, true);
|
|
||||||
if (RayTraceHelper.isRift(hit, worldIn)) {
|
|
||||||
EnumActionResult canDoorBePlacedOnGroundBelowRift
|
|
||||||
= tryPlaceDoorOnTopOfBlock(stack, playerIn, worldIn, hit.getBlockPos().down(2), handIn,
|
|
||||||
(float) hit.hitVec.x, (float) hit.hitVec.y, (float) hit.hitVec.z); //stack may be changed by this method
|
|
||||||
return new ActionResult<>(canDoorBePlacedOnGroundBelowRift, stack);
|
|
||||||
}
|
|
||||||
return new ActionResult<>(EnumActionResult.FAIL, stack); //@todo, should return onItemUse(params) here? will door placement on block not work otherwise?
|
|
||||||
|
|
||||||
//@todo personal and chaos doors can be placed on top of a rift? Should not be possible
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
|
||||||
if (worldIn.isRemote) {
|
|
||||||
return EnumActionResult.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block block = worldIn.getBlockState(pos).getBlock();
|
|
||||||
if (!block.isReplaceable(worldIn, pos)) {
|
|
||||||
if (facing != EnumFacing.UP) {
|
|
||||||
return EnumActionResult.FAIL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pos = pos.offset(EnumFacing.DOWN); //the bottom part of the door can replace this block, so we will try to place it on the block under it
|
|
||||||
}
|
|
||||||
|
|
||||||
return tryPlaceDoorOnTopOfBlock(player.getHeldItem(hand), player, worldIn, pos, hand, hitX, hitY, hitZ);
|
|
||||||
}
|
|
||||||
//pos = position of block, the door gets placed on
|
|
||||||
|
|
||||||
static EnumActionResult tryPlaceDoorOnTopOfBlock(ItemStack stack, EntityPlayer playerIn, World world, BlockPos pos, EnumHand hand, float hitX, float hitY, float hitZ) {
|
|
||||||
// Retrieve the actual door type that we want to use here.
|
|
||||||
// It's okay if stack isn't an ItemDoor. In that case, the lookup will
|
|
||||||
// return null, just as if the item was an unrecognized door type.
|
|
||||||
ItemDoorBase mappedItem = doorItemMapping.get(stack.getItem());
|
|
||||||
if (mappedItem == null) {
|
|
||||||
DimDoors.warn(ItemDoorBase.class, "Item " + stack.getItem() + " does not seem to have a valid mapped ItemDoor.");
|
|
||||||
return EnumActionResult.FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos = pos.up(); //change pos to position the bottom half of the door gets placed at
|
|
||||||
BlockDimDoorBase doorBlock = mappedItem.getDoorBlock();
|
|
||||||
if (playerIn.canPlayerEdit(pos, EnumFacing.UP, stack) && playerIn.canPlayerEdit(pos.up(), EnumFacing.UP, stack)
|
|
||||||
&& doorBlock.canPlaceBlockAt(world, pos)) {
|
|
||||||
//calculate what side the door should be facing
|
|
||||||
EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);
|
|
||||||
int i = enumfacing.getFrontOffsetX();
|
|
||||||
int j = enumfacing.getFrontOffsetZ();
|
|
||||||
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; //Vanilla Minecraft code not consistently using EnumFacing
|
|
||||||
//fetch "the" tile entity at the top block of where the door is going to be placed
|
|
||||||
TileEntity possibleOldRift = world.getTileEntity(pos.up());
|
|
||||||
if (possibleOldRift instanceof TileEntityFloatingRift) {
|
|
||||||
TileEntityFloatingRift oldRift = (TileEntityFloatingRift) possibleOldRift;
|
|
||||||
oldRift.placingDoorOnRift = true;
|
|
||||||
}
|
|
||||||
//place the door
|
|
||||||
placeDoor(world, pos, enumfacing, doorBlock, flag);
|
|
||||||
SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, playerIn);
|
|
||||||
world.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
|
||||||
if (!playerIn.isCreative()) {
|
|
||||||
stack.setCount(stack.getCount()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//fetch the TileEntityVerticalEntranceRift at the top block of where the door has just been placed
|
|
||||||
TileEntityVerticalEntranceRift newTileEntityVerticalEntranceRift = (TileEntityVerticalEntranceRift) world.getTileEntity(pos.up());
|
|
||||||
//set the tile-entity's initial data
|
|
||||||
// newTileEntityVerticalEntranceRift.uponDoorPlacement(possibleOldRift); // TODO
|
|
||||||
return EnumActionResult.SUCCESS;
|
|
||||||
} else {
|
|
||||||
return EnumActionResult.FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,7 @@ import java.util.Random;
|
||||||
public class PocketGenerator {
|
public class PocketGenerator {
|
||||||
|
|
||||||
public static Pocket generatePocketFromTemplate(int dimID, int depth, PocketTemplate pocketTemplate, VirtualLocation virtualLocation) {
|
public static Pocket generatePocketFromTemplate(int dimID, int depth, PocketTemplate pocketTemplate, VirtualLocation virtualLocation) {
|
||||||
DimDoors.log("depth = " + depth + " originalDim = " + virtualLocation);
|
DimDoors.log.info("depth = " + depth + " originalDim = " + virtualLocation);
|
||||||
|
|
||||||
PocketRegistry registry = PocketRegistry.getForDim(dimID);
|
PocketRegistry registry = PocketRegistry.getForDim(dimID);
|
||||||
Pocket pocket = registry.newPocket(depth);
|
Pocket pocket = registry.newPocket(depth);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class PocketRegistry extends WorldSavedData {
|
||||||
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
|
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
|
||||||
markDirty();
|
markDirty();
|
||||||
} else {
|
} else {
|
||||||
DimDoors.warn("Failed to upgrade the pocket registry, you'll have to recreate your world!");
|
DimDoors.log.fatal("Failed to upgrade the pocket registry, you'll have to recreate your world!");
|
||||||
throw new RuntimeException("Couldn't upgrade registry"); // TODO: better exceptions
|
throw new RuntimeException("Couldn't upgrade registry"); // TODO: better exceptions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,17 @@
|
||||||
package com.zixiken.dimdoors.shared.pockets;
|
package com.zixiken.dimdoors.shared.pockets;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.shared.tileentities.TileEntityVerticalEntranceRift;
|
|
||||||
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
|
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
|
||||||
import com.zixiken.dimdoors.shared.util.Location;
|
import com.zixiken.dimdoors.shared.util.Location;
|
||||||
import com.zixiken.dimdoors.shared.util.Schematic;
|
import com.zixiken.dimdoors.shared.util.Schematic;
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.minecraft.block.state.IBlockState;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
|
|
||||||
|
@ -22,91 +19,49 @@ import net.minecraft.world.WorldServer;
|
||||||
*
|
*
|
||||||
* @author Robijnvogel
|
* @author Robijnvogel
|
||||||
*/
|
*/
|
||||||
public class PocketTemplate { //there is exactly one pocket placer for each different schematic that is loaded into the game (a Json might load several schematics though)
|
@AllArgsConstructor @RequiredArgsConstructor// TODO: use @Builder?
|
||||||
|
public class PocketTemplate {
|
||||||
|
|
||||||
// TODO: access levels
|
|
||||||
//generation parameters
|
|
||||||
@Getter @Setter private Schematic schematic;
|
|
||||||
@Getter private final int size;
|
|
||||||
//selection parameters
|
|
||||||
@Getter private final String groupName;
|
@Getter private final String groupName;
|
||||||
@Getter private final String name;
|
@Getter private final String name;
|
||||||
|
@Getter @Setter private Schematic schematic;
|
||||||
|
@Getter private final int size; // size in chunks (n*n chunks)
|
||||||
@Getter private final int minDepth;
|
@Getter private final int minDepth;
|
||||||
@Getter private final int maxDepth;
|
@Getter private final int maxDepth;
|
||||||
private final float[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth"
|
private final float[] weights; // weight per-level
|
||||||
public static boolean schematicBeingPlaced = false;
|
|
||||||
|
|
||||||
//this class should contain the actual schematic info, as well as some of the Json info (placement of Rifts and stuff)
|
|
||||||
public PocketTemplate(String groupName, String name, Schematic schematic, int size, int minDepth, int maxDepth, float[] weights) {
|
|
||||||
this.groupName = groupName;
|
|
||||||
this.name = name;
|
|
||||||
this.weights = weights; //chance that this Pocket will get generated
|
|
||||||
this.minDepth = minDepth; //pocket will only be generated from this Pocket-depth
|
|
||||||
this.maxDepth = maxDepth; //to this pocket depth
|
|
||||||
this.size = size; //size of pocket in chunks (0 -> 1*1 chunk, 1 -> 2*2 chunks etc.)
|
|
||||||
this.schematic = schematic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PocketTemplate(String groupName, String name, int size, int minDepth, int maxDepth, float[] weights) {
|
|
||||||
this(groupName, name, null, size, minDepth, maxDepth, weights);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getWeight(int depth) {
|
public float getWeight(int depth) {
|
||||||
int index = depth - minDepth;
|
if (depth < 0) return 100; // TODO: get rid of this later
|
||||||
if (index >= 0 && index < weights.length) {
|
if (maxDepth - minDepth + 1 != weights.length) throw new IllegalStateException("This PocetTemplate wasn't set up correctly!");
|
||||||
return weights[index];
|
if (depth < minDepth) return 0;
|
||||||
}
|
if (depth > maxDepth) return weights[weights.length - 1];
|
||||||
return weights[weights.length - 1]; // return last weight
|
return weights[depth - minDepth];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pocket place(Pocket pocket, int yBase) { //returns the riftID of the entrance DimDoor TODO: use place method in schematic
|
public void place(Pocket pocket, int yBase) {
|
||||||
pocket.setSize(size);
|
pocket.setSize(size);
|
||||||
int gridSize = PocketRegistry.getForDim(pocket.dimID).getGridSize();
|
int gridSize = PocketRegistry.getForDim(pocket.dimID).getGridSize();
|
||||||
int dimID = pocket.dimID;
|
int dimID = pocket.dimID;
|
||||||
int xBase = pocket.getX() * gridSize * 16;
|
int xBase = pocket.getX() * gridSize * 16;
|
||||||
int zBase = pocket.getZ() * gridSize * 16;
|
int zBase = pocket.getZ() * gridSize * 16;
|
||||||
DimDoors.log(getClass(), "Placing new pocket at x = " + xBase + ", z = " + zBase);
|
DimDoors.log.info("Placing new pocket using schematic " + schematic.getSchematicName() + " at x = " + xBase + ", z = " + zBase);
|
||||||
DimDoors.log(getClass(), "Name of new pocket schematic is " + schematic.getSchematicName());
|
|
||||||
|
|
||||||
if (schematic == null) {
|
|
||||||
DimDoors.log(getClass(), "The schematic for variant " + name + " somehow didn't load correctly despite all precautions.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
//@todo make sure that the door tile entities get registered!
|
|
||||||
WorldServer world = DimDoors.proxy.getWorldServer(dimID);
|
WorldServer world = DimDoors.proxy.getWorldServer(dimID);
|
||||||
|
DimDoors.disableRiftSetup = true;
|
||||||
|
Schematic.place(schematic, world, xBase, yBase, zBase);
|
||||||
|
DimDoors.disableRiftSetup = false;
|
||||||
|
|
||||||
//Place the Dungeon content structure
|
// Set pocket riftLocations
|
||||||
schematicBeingPlaced = true; // TODO: Find a better system. What happens if the world is left before schematic is placed and this static field stays true?
|
pocket.riftLocations = new ArrayList<>();
|
||||||
List<IBlockState> palette = schematic.getPallette();
|
|
||||||
int[][][] blockData = schematic.getBlockData();
|
|
||||||
for (int x = 0; x < blockData.length; x++) {
|
|
||||||
for (int y = 0; y < blockData[x].length; y++) {
|
|
||||||
for (int z = 0; z < blockData[x][y].length; z++) {
|
|
||||||
world.setBlockState(new BlockPos(xBase + x, yBase + y, zBase + z), palette.get(blockData[x][y][z]), 2); //the "2" is to make non-default door-halves not break upon placement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
schematicBeingPlaced = false;
|
|
||||||
|
|
||||||
//Load TileEntity Data
|
|
||||||
List<Location> riftLocations = new ArrayList<>();
|
|
||||||
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
|
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
|
||||||
BlockPos pos = new BlockPos(xBase + tileEntityNBT.getInteger("x"), yBase + tileEntityNBT.getInteger("y"), zBase + tileEntityNBT.getInteger("z"));
|
BlockPos pos = new BlockPos(
|
||||||
DimDoors.log(getClass(), "Re-loading tile-entity at blockPos: " + pos);
|
xBase + tileEntityNBT.getInteger("x"),
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
yBase + tileEntityNBT.getInteger("y"),
|
||||||
if (tileEntity != null) {
|
zBase + tileEntityNBT.getInteger("z"));
|
||||||
tileEntity.readFromNBT(tileEntityNBT);
|
if (world.getTileEntity(pos) instanceof TileEntityRift) {
|
||||||
tileEntity.setWorld(world); // TODO: necessary?
|
DimDoors.log.info("Rift found in schematic at " + pos);
|
||||||
tileEntity.setPos(pos); //correct the position
|
pocket.riftLocations.add(new Location(world, pos));
|
||||||
|
|
||||||
if (tileEntity instanceof TileEntityRift) {
|
|
||||||
DimDoors.log(getClass(), "Rift found in schematic at " + pos);
|
|
||||||
riftLocations.add(new Location(world, pos));
|
|
||||||
}
|
|
||||||
tileEntity.markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pocket.riftLocations = riftLocations;
|
|
||||||
return pocket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class RiftRegistry extends WorldSavedData {
|
||||||
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
|
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
|
||||||
markDirty();
|
markDirty();
|
||||||
} else {
|
} else {
|
||||||
DimDoors.warn("Failed to upgrade the pocket registry, you'll have to recreate your world!");
|
DimDoors.log.warn("Failed to upgrade the pocket registry, you'll have to recreate your world!");
|
||||||
throw new RuntimeException("Couldn't upgrade registry"); // TODO: better exceptions
|
throw new RuntimeException("Couldn't upgrade registry"); // TODO: better exceptions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,9 +365,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
|
||||||
break;
|
break;
|
||||||
case POCKET_ENTRANCE:
|
case POCKET_ENTRANCE:
|
||||||
case POCKET_EXIT:
|
case POCKET_EXIT:
|
||||||
if (entity instanceof EntityPlayer) {
|
if (entity instanceof EntityPlayer) DimDoors.chat((EntityPlayer) entity, "The entrance/exit of this dungeon has not been linked. Either this is a bug or you are in dungeon-building mode.");
|
||||||
DimDoors.chat((EntityPlayer) entity, "The entrance/exit of this dungeon has not been linked. Either this is a bug or you are in dungeon-building mode.");
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("That rift type is not implemented in TileRiftEntity.teleport, this is a bug.");
|
throw new RuntimeException("That rift type is not implemented in TileRiftEntity.teleport, this is a bug.");
|
||||||
|
@ -388,7 +386,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (entity instanceof EntityPlayer) DimDoors.chat((EntityPlayer) entity, "There was an exception while teleporting!");
|
if (entity instanceof EntityPlayer) DimDoors.chat((EntityPlayer) entity, "There was an exception while teleporting!");
|
||||||
e.printStackTrace();
|
DimDoors.log.error("Teleporting failed with the following exception: ", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,5 +462,4 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isEntrance(); // TODO: replace with chooseWeight function
|
public abstract boolean isEntrance(); // TODO: replace with chooseWeight function
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class RandomUtils {
|
||||||
throw new IllegalArgumentException("pre was violated");
|
throw new IllegalArgumentException("pre was violated");
|
||||||
}
|
}
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
DimDoors.log(RandomUtils.class, "base = " + base + ", power = " + power + ", depth = " + depth + " and power is " + Math.pow(base * depth, power));
|
DimDoors.log.info("base = " + base + ", power = " + power + ", depth = " + depth + " and power is " + Math.pow(base * depth, power));
|
||||||
int xOffset = random.nextInt((int) Math.pow(base * depth, power)) * (random.nextBoolean() ? 1 : -1);
|
int xOffset = random.nextInt((int) Math.pow(base * depth, power)) * (random.nextBoolean() ? 1 : -1);
|
||||||
int zOffset = random.nextInt((int) Math.pow(base * depth, power)) * (random.nextBoolean() ? 1 : -1);
|
int zOffset = random.nextInt((int) Math.pow(base * depth, power)) * (random.nextBoolean() ? 1 : -1);
|
||||||
return new Location(origLocation.getWorld(), origLocation.getPos().offset(EnumFacing.EAST, xOffset).offset(EnumFacing.SOUTH, zOffset));
|
return new Location(origLocation.getWorld(), origLocation.getPos().offset(EnumFacing.EAST, xOffset).offset(EnumFacing.SOUTH, zOffset));
|
||||||
|
|
|
@ -244,10 +244,14 @@ public class Schematic {
|
||||||
|
|
||||||
// Set TileEntity data
|
// Set TileEntity data
|
||||||
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
|
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
|
||||||
BlockPos pos = new BlockPos(xBase + tileEntityNBT.getInteger("x"), yBase + tileEntityNBT.getInteger("y"), zBase + tileEntityNBT.getInteger("z"));
|
BlockPos pos = new BlockPos(
|
||||||
|
xBase + tileEntityNBT.getInteger("x"),
|
||||||
|
yBase + tileEntityNBT.getInteger("y"),
|
||||||
|
zBase + tileEntityNBT.getInteger("z"));
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
TileEntity tileEntity = world.getTileEntity(pos);
|
||||||
if (tileEntity != null) {
|
if (tileEntity != null) {
|
||||||
tileEntity.readFromNBT(tileEntityNBT); //this reads in the wrong blockPos
|
tileEntity.readFromNBT(tileEntityNBT); //this reads in the wrong blockPos
|
||||||
|
tileEntity.setWorld(world); // TODO: necessary?
|
||||||
tileEntity.setPos(pos); //correct the position
|
tileEntity.setPos(pos); //correct the position
|
||||||
tileEntity.markDirty();
|
tileEntity.markDirty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class SchematicConverter {
|
||||||
if (nbt.hasKey("Palette")) {
|
if (nbt.hasKey("Palette")) {
|
||||||
NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette");
|
NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette");
|
||||||
for (int i = 0; i < paletteNBT.tagCount(); i++) {
|
for (int i = 0; i < paletteNBT.tagCount(); i++) {
|
||||||
//DimDoors.log(Schematic.class, "reading pallete from schematic... i = " + i);
|
//DimDoors.log.info("reading pallete from schematic... i = " + i);
|
||||||
String blockString = paletteNBT.getStringTagAt(i);
|
String blockString = paletteNBT.getStringTagAt(i);
|
||||||
boolean isAncientFabric = false;
|
boolean isAncientFabric = false;
|
||||||
if (blockString.startsWith("dimdoors")) {
|
if (blockString.startsWith("dimdoors")) {
|
||||||
|
@ -124,11 +124,11 @@ public class SchematicConverter {
|
||||||
blockInt = schematic.pallette.indexOf(additionalState);
|
blockInt = schematic.pallette.indexOf(additionalState);
|
||||||
} else {
|
} else {
|
||||||
schematic.pallette.add(additionalState);
|
schematic.pallette.add(additionalState);
|
||||||
// DimDoors.log(Schematic.class, "New blockstate detected. Original blockInt = " + blockInt + " and baseState is " + baseState);
|
// DimDoors.log.info("New blockstate detected. Original blockInt = " + blockInt + " and baseState is " + baseState);
|
||||||
blockInt = schematic.pallette.size() - 1;
|
blockInt = schematic.pallette.size() - 1;
|
||||||
}
|
}
|
||||||
} else { //if this is ancient fabric
|
} else { //if this is ancient fabric
|
||||||
// DimDoors.log(Schematic.class, "Non-default blockstate in palette detected. Original blockInt = " + blockInt + " and baseState is " + baseState.toString()); //@todo should only print a line on load of ancient fabric
|
// DimDoors.log.info("Non-default blockstate in palette detected. Original blockInt = " + blockInt + " and baseState is " + baseState.toString()); //@todo should only print a line on load of ancient fabric
|
||||||
blockInt = schematic.pallette.indexOf(baseState);
|
blockInt = schematic.pallette.indexOf(baseState);
|
||||||
}
|
}
|
||||||
schematic.blockData[x][y][z] = blockInt;
|
schematic.blockData[x][y][z] = blockInt;
|
||||||
|
@ -148,7 +148,7 @@ public class SchematicConverter {
|
||||||
|
|
||||||
private static String convertOldDimDoorsBlockNameToNewDimDoorsBlockName(String dimdoorsBlockName) {
|
private static String convertOldDimDoorsBlockNameToNewDimDoorsBlockName(String dimdoorsBlockName) {
|
||||||
if (OLDDIMDOORBLOCKNAMES.length != NEWDIMDOORBLOCKNAMES.length) {
|
if (OLDDIMDOORBLOCKNAMES.length != NEWDIMDOORBLOCKNAMES.length) {
|
||||||
DimDoors.warn(Schematic.class, "The array of old DimDoors block names somehow isn't the same length as the array of new names, therefore the dimdoors blocks in this schematic will not be loaded. This is a bug in the DimDoors mod itself.");
|
DimDoors.log.error("The array of old DimDoors block names somehow isn't the same length as the array of new names, therefore the dimdoors blocks in this schematic will not be loaded. This is a bug in the DimDoors mod itself.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ public class SchematicConverter {
|
||||||
return NEWDIMDOORBLOCKNAMES[i];
|
return NEWDIMDOORBLOCKNAMES[i];
|
||||||
} else {
|
} else {
|
||||||
if (i == OLDDIMDOORBLOCKNAMES.length - 1) {
|
if (i == OLDDIMDOORBLOCKNAMES.length - 1) {
|
||||||
DimDoors.warn(Schematic.class, dimdoorsBlockName + " as an old dimdoors block name is unknown.");
|
DimDoors.log.warn(dimdoorsBlockName + " as an old dimdoors block name is unknown.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.zixiken.dimdoors.shared.world.gateways;
|
package com.zixiken.dimdoors.shared.world.gateways;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.SchematicHandler;
|
|
||||||
import com.zixiken.dimdoors.shared.util.Schematic;
|
import com.zixiken.dimdoors.shared.util.Schematic;
|
||||||
import com.zixiken.dimdoors.shared.util.SchematicConverter;
|
import com.zixiken.dimdoors.shared.util.SchematicConverter;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
|
@ -11,8 +10,6 @@ import net.minecraft.world.World;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public abstract class BaseSchematicGateway extends BaseGateway {
|
public abstract class BaseSchematicGateway extends BaseGateway {
|
||||||
private Schematic schematic;
|
private Schematic schematic;
|
||||||
|
@ -30,23 +27,23 @@ public abstract class BaseSchematicGateway extends BaseGateway {
|
||||||
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
|
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
|
||||||
streamOpened = true;
|
streamOpened = true;
|
||||||
} else {
|
} else {
|
||||||
DimDoors.warn(SchematicHandler.class, "Schematic '" + name + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
|
DimDoors.log.warn("Schematic '" + name + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound schematicNBT;
|
NBTTagCompound schematicNBT;
|
||||||
this.schematic = null;
|
schematic = null;
|
||||||
if (streamOpened) {
|
if (streamOpened) {
|
||||||
try {
|
try {
|
||||||
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
|
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
|
||||||
schematic = SchematicConverter.loadOldDimDoorSchematicFromNBT(schematicNBT, name);
|
schematic = SchematicConverter.loadOldDimDoorSchematicFromNBT(schematicNBT, name);
|
||||||
schematicDataStream.close();
|
schematicDataStream.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file for " + name + " could not be read as a valid schematic NBT file.", ex);
|
DimDoors.log.error("Schematic file for " + name + " could not be read as a valid schematic NBT file.", ex);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
schematicDataStream.close();
|
schematicDataStream.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Error occured while closing schematicDataStream", ex);
|
DimDoors.log.error("Error occured while closing schematicDataStream", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +52,7 @@ public abstract class BaseSchematicGateway extends BaseGateway {
|
||||||
@Override
|
@Override
|
||||||
public boolean generate(World world, int x, int y, int z) {
|
public boolean generate(World world, int x, int y, int z) {
|
||||||
Schematic.place(schematic, world, x, y, z);
|
Schematic.place(schematic, world, x, y, z);
|
||||||
this.generateRandomBits(world, x, y, z);
|
generateRandomBits(world, x, y, z);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue