Improvements

- Remove some unused code
 - Better logging
 - Bug fixes
 - Unify pocket placing and gateway placing code
This commit is contained in:
Runemoro 2017-12-17 05:40:45 -05:00
parent cc952a642f
commit 915bc41a08
24 changed files with 93 additions and 323 deletions

View file

@ -19,23 +19,27 @@ import net.minecraftforge.fml.common.event.*;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.Logger;
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 static final String MODID = "dimdoors";
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",
serverSide = "com.zixiken.dimdoors.server.DDProxyServer")
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") {
@Override
@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
public void onPreInitialization(FMLPreInitializationEvent event) {
log = event.getModLog();
proxy.onPreInitialization(event);
DDConfig.loadConfig(event);
}
@ -80,30 +88,6 @@ public class DimDoors {
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
public static void translateAndAdd(String key, List<String> list) {
for (int i = 0; i < 10; i++) {

View file

@ -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.");
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);
DimDoors.log(DDConfig.class, "pocketGridSize was set to " + pocketGridSize);
DimDoors.log.info("pocketGridSize was set to " + pocketGridSize);
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));

View file

@ -19,7 +19,7 @@ public abstract class DDProxyCommon implements IDDProxy {
@Override
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(ModItems.class);
MinecraftForge.EVENT_BUS.register(CraftingManager.class); // TODO: ModRecipes?

View file

@ -12,10 +12,10 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class DDEventHandler {
public class EventHandler {
@SubscribeEvent
public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
public static void onPlayerJoinWorld(EntityJoinWorldEvent event) {
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 (!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
public void onLivingFall(LivingFallEvent event) {
public static void onLivingFall(LivingFallEvent event) {
Entity entity = event.getEntity();
if (entity.dimension == DimDoorDimensions.LIMBO.getId()) {
event.setCanceled(true); // no fall damage in limbo
@ -34,7 +34,7 @@ public class DDEventHandler {
}
@SubscribeEvent
public void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
public static void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
Entity entity = event.getEntity();
if (entity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entity;

View file

@ -69,12 +69,12 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
String jsonString = IOUtils.toString(file.toURI(), StandardCharsets.UTF_8);
templates.addAll(loadTemplatesFromJson(jsonString));
} 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();
DimDoors.log("Loaded " + templates.size() + " templates.");
DimDoors.log.info("Loaded " + templates.size() + " templates.");
}
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();
JsonElement jsonElement = parser.parse(jsonString);
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"
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
@ -115,17 +115,17 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
schematicDataStream = new DataInputStream(new FileInputStream(schematicFile));
streamOpened = true;
} 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()) {
try {
schematicDataStream = new DataInputStream(new FileInputStream(oldVersionSchematicFile));
streamOpened = true;
} 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 {
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;
@ -153,9 +153,10 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
if (schematic != null
&& (schematic.getWidth() > (template.getSize() + 1) * 16 || schematic.getLength() > (template.getSize() + 1) * 16)) {
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);
// TODO: delete from validTemplates if schematic is null
}
return validTemplates;
}
@ -274,7 +275,7 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
}
}
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
}

View file

@ -6,7 +6,6 @@ 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.pockets.PocketTemplate;
import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
@ -122,7 +121,7 @@ public abstract class BlockDimDoorBase extends BlockDoor implements ITileEntityP
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState 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));
// Set the virtual location based on where the door was placed

View file

@ -65,7 +65,7 @@ public class CommandDimTeleport extends CommandBase { // TODO: localization
if (sender instanceof Entity) {
TeleportUtils.teleport((Entity) sender, new Location(dimension, new BlockPos(x, y, z)), yaw, pitch);
} 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.");
}
}

View file

@ -60,7 +60,7 @@ public class PocketCommand extends CommandBase {
}
}
} 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.");
}
}

View file

@ -108,7 +108,7 @@ public class RenderMonolith extends RenderLiving<EntityMonolith> {
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
} catch (Exception e) {
e.printStackTrace();
DimDoors.log.error(e);
}
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);

View file

@ -4,10 +4,8 @@ import java.util.List;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorIron;
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.init.Items;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -15,10 +13,10 @@ import net.minecraft.world.World;
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
public class ItemDimDoor extends ItemDoorBase {
public class ItemDimDoor extends ItemDoor {
public ItemDimDoor() {
super(ModBlocks.DIMENSIONAL_DOOR, (ItemDoor) Items.IRON_DOOR);
super(ModBlocks.DIMENSIONAL_DOOR);
setUnlocalizedName(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) {
translateAndAdd("info.dimensional_door", tooltip);
}
@Override
protected BlockDimDoorBase getDoorBlock() {
return ModBlocks.DIMENSIONAL_DOOR;
}
}

View file

@ -3,20 +3,20 @@ package com.zixiken.dimdoors.shared.items;
import java.util.List;
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.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 ItemDimDoorGold extends ItemDoorBase {
public class ItemDimDoorGold extends ItemDoor {
public ItemDimDoorGold() {
super(ModBlocks.GOLD_DIMENSIONAL_DOOR, ModItems.GOLD_DOOR);
super(ModBlocks.GOLD_DIMENSIONAL_DOOR);
setUnlocalizedName(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) {
translateAndAdd("info.gold_dimensional_door", tooltip);
}
@Override
protected BlockDimDoorBase getDoorBlock() {
return ModBlocks.GOLD_DIMENSIONAL_DOOR;
}
}

View file

@ -3,20 +3,20 @@ package com.zixiken.dimdoors.shared.items;
import java.util.List;
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.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 ItemDoorBase {
public class ItemDimDoorPersonal extends ItemDoor {
public ItemDimDoorPersonal() {
super(ModBlocks.PERSONAL_DIMENSIONAL_DOOR, ModItems.QUARTZ_DOOR);
super(ModBlocks.PERSONAL_DIMENSIONAL_DOOR);
setUnlocalizedName(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) {
translateAndAdd("info.quartz_dimensional_door", tooltip);
}
@Override
protected BlockDimDoorBase getDoorBlock() {
return ModBlocks.PERSONAL_DIMENSIONAL_DOOR;
}
}

View file

@ -3,20 +3,20 @@ package com.zixiken.dimdoors.shared.items;
import java.util.List;
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.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 ItemDoorBase {
public class ItemDimDoorUnstable extends ItemDoor {
public ItemDimDoorUnstable() {
super(ModBlocks.UNSTABLE_DIMENSIONAL_DOOR, null);
super(ModBlocks.UNSTABLE_DIMENSIONAL_DOOR);
setUnlocalizedName(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) {
translateAndAdd("info.unstable_dimensional_door", tooltip);
}
@Override
protected BlockDimDoorBase getDoorBlock() {
return ModBlocks.UNSTABLE_DIMENSIONAL_DOOR;
}
}

View file

@ -3,11 +3,9 @@ package com.zixiken.dimdoors.shared.items;
import java.util.List;
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.ModBlocks;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.init.Items;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -15,10 +13,10 @@ import net.minecraft.world.World;
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
public class ItemDimDoorWarp extends ItemDoorBase {
public class ItemDimDoorWarp extends ItemDoor {
public ItemDimDoorWarp() {
super(ModBlocks.WARP_DIMENSIONAL_DOOR, (ItemDoor) Items.OAK_DOOR);
super(ModBlocks.WARP_DIMENSIONAL_DOOR);
setUnlocalizedName(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) {
translateAndAdd("info.warp_dimensional_door", tooltip);
}
@Override
protected BlockDimDoorBase getDoorBlock() {
return ModBlocks.WARP_DIMENSIONAL_DOOR;
}
}

View file

@ -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;
}
}
}

View file

@ -9,7 +9,7 @@ import java.util.Random;
public class PocketGenerator {
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);
Pocket pocket = registry.newPocket(depth);

View file

@ -75,7 +75,7 @@ public class PocketRegistry extends WorldSavedData {
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
markDirty();
} 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
}
}

View file

@ -1,20 +1,17 @@
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.util.Location;
import com.zixiken.dimdoors.shared.util.Schematic;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
@ -22,91 +19,49 @@ import net.minecraft.world.WorldServer;
*
* @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 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 maxDepth;
private final float[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth"
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);
}
private final float[] weights; // weight per-level
public float getWeight(int depth) {
int index = depth - minDepth;
if (index >= 0 && index < weights.length) {
return weights[index];
}
return weights[weights.length - 1]; // return last weight
if (depth < 0) return 100; // TODO: get rid of this later
if (maxDepth - minDepth + 1 != weights.length) throw new IllegalStateException("This PocetTemplate wasn't set up correctly!");
if (depth < minDepth) return 0;
if (depth > maxDepth) return weights[weights.length - 1];
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);
int gridSize = PocketRegistry.getForDim(pocket.dimID).getGridSize();
int dimID = pocket.dimID;
int xBase = pocket.getX() * gridSize * 16;
int zBase = pocket.getZ() * gridSize * 16;
DimDoors.log(getClass(), "Placing new pocket at x = " + xBase + ", z = " + zBase);
DimDoors.log(getClass(), "Name of new pocket schematic is " + schematic.getSchematicName());
DimDoors.log.info("Placing new pocket using schematic " + schematic.getSchematicName() + " at x = " + xBase + ", z = " + zBase);
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);
DimDoors.disableRiftSetup = true;
Schematic.place(schematic, world, xBase, yBase, zBase);
DimDoors.disableRiftSetup = false;
//Place the Dungeon content structure
schematicBeingPlaced = true; // TODO: Find a better system. What happens if the world is left before schematic is placed and this static field stays true?
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<>();
// Set pocket riftLocations
pocket.riftLocations = new ArrayList<>();
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
BlockPos pos = new BlockPos(xBase + tileEntityNBT.getInteger("x"), yBase + tileEntityNBT.getInteger("y"), zBase + tileEntityNBT.getInteger("z"));
DimDoors.log(getClass(), "Re-loading tile-entity at blockPos: " + pos);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
tileEntity.readFromNBT(tileEntityNBT);
tileEntity.setWorld(world); // TODO: necessary?
tileEntity.setPos(pos); //correct the position
if (tileEntity instanceof TileEntityRift) {
DimDoors.log(getClass(), "Rift found in schematic at " + pos);
riftLocations.add(new Location(world, pos));
}
tileEntity.markDirty();
BlockPos pos = new BlockPos(
xBase + tileEntityNBT.getInteger("x"),
yBase + tileEntityNBT.getInteger("y"),
zBase + tileEntityNBT.getInteger("z"));
if (world.getTileEntity(pos) instanceof TileEntityRift) {
DimDoors.log.info("Rift found in schematic at " + pos);
pocket.riftLocations.add(new Location(world, pos));
}
}
pocket.riftLocations = riftLocations;
return pocket;
}
}

View file

@ -143,7 +143,7 @@ public class RiftRegistry extends WorldSavedData {
if (upgradeRegistry(nbt, version == null ? -1 : version)) {
markDirty();
} 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
}
}

View file

@ -365,9 +365,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
break;
case POCKET_ENTRANCE:
case POCKET_EXIT:
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.");
}
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.");
return false;
default:
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) {
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;
}
}
@ -464,5 +462,4 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
}
public abstract boolean isEntrance(); // TODO: replace with chooseWeight function
}

View file

@ -85,7 +85,7 @@ public class RandomUtils {
throw new IllegalArgumentException("pre was violated");
}
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 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));

View file

@ -244,10 +244,14 @@ public class Schematic {
// Set TileEntity data
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);
if (tileEntity != null) {
tileEntity.readFromNBT(tileEntityNBT); //this reads in the wrong blockPos
tileEntity.setWorld(world); // TODO: necessary?
tileEntity.setPos(pos); //correct the position
tileEntity.markDirty();
}

View file

@ -50,7 +50,7 @@ public class SchematicConverter {
if (nbt.hasKey("Palette")) {
NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette");
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);
boolean isAncientFabric = false;
if (blockString.startsWith("dimdoors")) {
@ -124,11 +124,11 @@ public class SchematicConverter {
blockInt = schematic.pallette.indexOf(additionalState);
} else {
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;
}
} 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);
}
schematic.blockData[x][y][z] = blockInt;
@ -148,7 +148,7 @@ public class SchematicConverter {
private static String convertOldDimDoorsBlockNameToNewDimDoorsBlockName(String dimdoorsBlockName) {
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;
}
@ -158,7 +158,7 @@ public class SchematicConverter {
return NEWDIMDOORBLOCKNAMES[i];
} else {
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.");
}
}
}

View file

@ -1,7 +1,6 @@
package com.zixiken.dimdoors.shared.world.gateways;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.SchematicHandler;
import com.zixiken.dimdoors.shared.util.Schematic;
import com.zixiken.dimdoors.shared.util.SchematicConverter;
import net.minecraft.nbt.CompressedStreamTools;
@ -11,8 +10,6 @@ import net.minecraft.world.World;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class BaseSchematicGateway extends BaseGateway {
private Schematic schematic;
@ -30,23 +27,23 @@ public abstract class BaseSchematicGateway extends BaseGateway {
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
streamOpened = true;
} 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;
this.schematic = null;
schematic = null;
if (streamOpened) {
try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
schematic = SchematicConverter.loadOldDimDoorSchematicFromNBT(schematicNBT, name);
schematicDataStream.close();
} 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 {
try {
schematicDataStream.close();
} 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
public boolean generate(World world, int x, int y, int z) {
Schematic.place(schematic, world, x, y, z);
this.generateRandomBits(world, x, y, z);
generateRandomBits(world, x, y, z);
return true;