Skip to content

Commit 915bc41

Browse files
committed
Improvements
- Remove some unused code - Better logging - Bug fixes - Unify pocket placing and gateway placing code
1 parent cc952a6 commit 915bc41

24 files changed

Lines changed: 93 additions & 323 deletions

src/main/java/com/zixiken/dimdoors/DimDoors.java

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@
1919
import net.minecraftforge.fml.common.registry.GameRegistry;
2020
import net.minecraftforge.fml.relauncher.Side;
2121
import net.minecraftforge.fml.relauncher.SideOnly;
22+
import org.apache.logging.log4j.Logger;
2223

2324
import java.util.List;
2425

25-
@Mod(modid = DimDoors.MODID, name = "Dimensional Doors", version = DimDoors.VERSION, dependencies = "required-after:forge@[14.23.0.2517,)")
26+
@Mod(modid = DimDoors.MODID, name = "Dimensional Doors",
27+
version = DimDoors.VERSION,
28+
dependencies = "required-after:forge@[14.23.0.2517,)")
2629
public class DimDoors {
2730

2831
public static final String MODID = "dimdoors";
2932
public static final String VERSION = "${version}";
30-
@Getter private GatewayGenerator gatewayGenerator;
33+
34+
@Mod.Instance(DimDoors.MODID)
35+
public static DimDoors instance;
36+
37+
public static Logger log; // TODO: make non-static?
3138

3239
@SidedProxy(clientSide = "com.zixiken.dimdoors.client.DDProxyClient",
3340
serverSide = "com.zixiken.dimdoors.server.DDProxyServer")
3441
public static DDProxyCommon proxy;
3542

36-
@Mod.Instance(DimDoors.MODID)
37-
public static DimDoors instance;
38-
3943
public static final CreativeTabs DIM_DOORS_CREATIVE_TAB = new CreativeTabs("dimensional_doors_creative_tab") {
4044
@Override
4145
@SideOnly(Side.CLIENT)
@@ -44,9 +48,13 @@ public ItemStack getTabIconItem() {
4448
}
4549
};
4650

51+
@Getter private GatewayGenerator gatewayGenerator;
52+
53+
public static boolean disableRiftSetup = false; // TODO: Find a better system.
4754

4855
@Mod.EventHandler
4956
public void onPreInitialization(FMLPreInitializationEvent event) {
57+
log = event.getModLog();
5058
proxy.onPreInitialization(event);
5159
DDConfig.loadConfig(event);
5260
}
@@ -80,30 +88,6 @@ public static void chat(EntityPlayer player, String text) {
8088
player.sendMessage(new TextComponentString("[DimDoors] " + text));
8189
}
8290

83-
public static void warn(String text) {
84-
warn(null, text);
85-
}
86-
87-
public static void warn(Class<?> classFiredFrom, String text) {
88-
if(classFiredFrom != null) {
89-
FMLLog.log.warn("[DimDoors] " + text + " (" + classFiredFrom + " )", 0);
90-
} else {
91-
FMLLog.log.warn("[DimDoors] " + text, 0);
92-
}
93-
}
94-
95-
public static void log(String text) {
96-
log(null, text);
97-
}
98-
99-
public static void log(Class<?> classFiredFrom, String text) {
100-
if(classFiredFrom != null) {
101-
FMLLog.log.info("[DimDoors] " + text + " (" + classFiredFrom + " )", 0);
102-
} else {
103-
FMLLog.log.info("[DimDoors] " + text, 0);
104-
}
105-
}
106-
10791
// TODO: I18n is deprecated, convert to TextComponentTranslation
10892
public static void translateAndAdd(String key, List<String> list) {
10993
for (int i = 0; i < 10; i++) {

src/main/java/com/zixiken/dimdoors/shared/DDConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static void loadConfig(FMLPreInitializationEvent event) {
110110
config.addCustomCategoryComment("pocket_dimension", "The following values determine the maximum sizes of different kinds of pockets. These values will only influence new worlds.");
111111
pocketGridSize = setConfigIntWithMaxAndMin(config, "pocket_dimension", "pocketGridSize", pocketGridSize,
112112
"Sets how many chunks apart all pockets in pocket dimensions should be placed. [min: 4, max: 32, default: 32]", 4, 32);
113-
DimDoors.log(DDConfig.class, "pocketGridSize was set to " + pocketGridSize);
113+
DimDoors.log.info("pocketGridSize was set to " + pocketGridSize);
114114

115115
maxPocketSize = setConfigIntWithMaxAndMin(config, "pocket_dimension", "maxPocketSize", maxPocketSize,
116116
"Sets how deep and wide any pocket can be. [min: 0, max: pocketGridSize/2, default: 4]", 0, (int) ((double) pocketGridSize / 2 - 0.5));

src/main/java/com/zixiken/dimdoors/shared/DDProxyCommon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class DDProxyCommon implements IDDProxy {
1919

2020
@Override
2121
public void onPreInitialization(FMLPreInitializationEvent event) {
22-
MinecraftForge.EVENT_BUS.register(new DDEventHandler());
22+
MinecraftForge.EVENT_BUS.register(EventHandler.class);
2323
MinecraftForge.EVENT_BUS.register(ModBlocks.class);
2424
MinecraftForge.EVENT_BUS.register(ModItems.class);
2525
MinecraftForge.EVENT_BUS.register(CraftingManager.class); // TODO: ModRecipes?

src/main/java/com/zixiken/dimdoors/shared/DDEventHandler.java renamed to src/main/java/com/zixiken/dimdoors/shared/EventHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import net.minecraftforge.event.entity.living.LivingFallEvent;
1313
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
1414

15-
public class DDEventHandler {
15+
public class EventHandler {
1616

1717
@SubscribeEvent
18-
public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
18+
public static void onPlayerJoinWorld(EntityJoinWorldEvent event) {
1919
Entity entity = event.getEntity();
2020
if(entity instanceof EntityPlayer && !entity.world.isRemote) { // check that it's a player first to avoid calling String.contains for every entity
2121
if (!DDConfig.HAVE_CONFIG_DEFAULTS_BEEN_CHECKED_FOR_CORRECTNESS && !DimDoors.VERSION.contains("a")) { // default values were not checked in non-alpha version
@@ -26,15 +26,15 @@ public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
2626
}
2727

2828
@SubscribeEvent
29-
public void onLivingFall(LivingFallEvent event) {
29+
public static void onLivingFall(LivingFallEvent event) {
3030
Entity entity = event.getEntity();
3131
if (entity.dimension == DimDoorDimensions.LIMBO.getId()) {
3232
event.setCanceled(true); // no fall damage in limbo
3333
}
3434
}
3535

3636
@SubscribeEvent
37-
public void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
37+
public static void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
3838
Entity entity = event.getEntity();
3939
if (entity instanceof EntityPlayerMP) {
4040
EntityPlayerMP player = (EntityPlayerMP) entity;

src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public void loadSchematics() {
6969
String jsonString = IOUtils.toString(file.toURI(), StandardCharsets.UTF_8);
7070
templates.addAll(loadTemplatesFromJson(jsonString));
7171
} catch (IOException e) {
72-
DimDoors.warn("Error reading file " + file.toURI() + ". The following exception occured: ");
72+
DimDoors.log.error("Error reading file " + file.toURI() + ". The following exception occured: ", e);
7373
}
7474
}
7575
constructNameMap();
7676

77-
DimDoors.log("Loaded " + templates.size() + " templates.");
77+
DimDoors.log.info("Loaded " + templates.size() + " templates.");
7878
}
7979

8080
private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
@@ -84,11 +84,11 @@ private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
8484
JsonParser parser = new JsonParser();
8585
JsonElement jsonElement = parser.parse(jsonString);
8686
JsonObject jsonTemplate = jsonElement.getAsJsonObject();
87-
//DimDoors.log(SchematicHandler.class, "Checkpoint 1 reached");
87+
//DimDoors.log.info("Checkpoint 1 reached");
8888

8989
//Generate and get templates (without a schematic) of all variations that are valid for the current "maxPocketSize"
9090
List<PocketTemplate> validTemplates = getAllValidVariations(jsonTemplate);
91-
//DimDoors.log(SchematicHandler.class, "Checkpoint 4 reached; " + validTemplates.size() + " templates were loaded");
91+
//DimDoors.log.info("Checkpoint 4 reached; " + validTemplates.size() + " templates were loaded");
9292

9393
String subDirectory = jsonTemplate.get("group").getAsString(); //get the subfolder in which the schematics are stored
9494

@@ -115,17 +115,17 @@ private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
115115
schematicDataStream = new DataInputStream(new FileInputStream(schematicFile));
116116
streamOpened = true;
117117
} catch (FileNotFoundException ex) {
118-
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schem did not load correctly from config folder.", ex);
118+
DimDoors.log.error("Schematic file " + template.getName() + ".schem did not load correctly from config folder.", ex);
119119
}
120120
} else if (oldVersionSchematicFile.exists()) {
121121
try {
122122
schematicDataStream = new DataInputStream(new FileInputStream(oldVersionSchematicFile));
123123
streamOpened = true;
124124
} catch (FileNotFoundException ex) {
125-
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex);
125+
DimDoors.log.error("Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex);
126126
}
127127
} else {
128-
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.");
128+
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.");
129129
}
130130

131131
NBTTagCompound schematicNBT;
@@ -153,9 +153,10 @@ private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
153153
if (schematic != null
154154
&& (schematic.getWidth() > (template.getSize() + 1) * 16 || schematic.getLength() > (template.getSize() + 1) * 16)) {
155155
schematic = null;
156-
DimDoors.log(SchematicHandler.class, "Schematic " + template.getName() + " was bigger than specified in its json file and therefore wasn't loaded");
156+
DimDoors.log.warn("Schematic " + template.getName() + " was bigger than specified in its json file and therefore wasn't loaded");
157157
}
158158
template.setSchematic(schematic);
159+
// TODO: delete from validTemplates if schematic is null
159160
}
160161
return validTemplates;
161162
}
@@ -274,7 +275,7 @@ public PocketTemplate getRandomTemplate(String group, int depth, int maxSize, bo
274275
}
275276
}
276277
if (weightedTemplates.size() == 0) {
277-
DimDoors.warn("getRandomTemplate failed, no templates matching those criteria were found.");
278+
DimDoors.log.warn("getRandomTemplate failed, no templates matching those criteria were found.");
278279
return null; // TODO: switch to exception system
279280
}
280281

src/main/java/com/zixiken/dimdoors/shared/blocks/BlockDimDoorBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.zixiken.dimdoors.shared.VirtualLocation;
77
import com.zixiken.dimdoors.shared.pockets.Pocket;
88
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
9-
import com.zixiken.dimdoors.shared.pockets.PocketTemplate;
109
import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
1110
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
1211
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
@@ -122,7 +121,7 @@ public TileEntityVerticalEntranceRift createNewTileEntity(World worldIn, int met
122121
@Override
123122
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
124123
super.onBlockAdded(worldIn, pos, state);
125-
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)
124+
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)
126125
TileEntityVerticalEntranceRift rift = createNewTileEntity(worldIn, getMetaFromState(state));
127126

128127
// Set the virtual location based on where the door was placed

src/main/java/com/zixiken/dimdoors/shared/commands/CommandDimTeleport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
6565
if (sender instanceof Entity) {
6666
TeleportUtils.teleport((Entity) sender, new Location(dimension, new BlockPos(x, y, z)), yaw, pitch);
6767
} else {
68-
DimDoors.log("Not executing command /" + getName() + " because it wasn't sent by a player.");
68+
DimDoors.log.info("Not executing command /" + getName() + " because it wasn't sent by a player.");
6969
}
7070
}
7171

src/main/java/com/zixiken/dimdoors/shared/commands/PocketCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
6060
}
6161
}
6262
} else {
63-
DimDoors.log("Not executing command /" + getName() + " because it wasn't sent by a player.");
63+
DimDoors.log.info("Not executing command /" + getName() + " because it wasn't sent by a player.");
6464
}
6565
}
6666

src/main/java/com/zixiken/dimdoors/shared/entities/RenderMonolith.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void render(EntityMonolith par1EntityLivingBase, double x, double y, doub
108108

109109
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
110110
} catch (Exception e) {
111-
e.printStackTrace();
111+
DimDoors.log.error(e);
112112
}
113113

114114
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);

src/main/java/com/zixiken/dimdoors/shared/items/ItemDimDoor.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44

55
import com.zixiken.dimdoors.DimDoors;
66
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorIron;
7-
import com.zixiken.dimdoors.shared.blocks.BlockDimDoorBase;
87
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
98
import net.minecraft.client.util.ITooltipFlag;
10-
import net.minecraft.init.Items;
119
import net.minecraft.item.ItemDoor;
1210
import net.minecraft.item.ItemStack;
1311
import net.minecraft.util.ResourceLocation;
1412
import net.minecraft.world.World;
1513

1614
import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
1715

18-
public class ItemDimDoor extends ItemDoorBase {
16+
public class ItemDimDoor extends ItemDoor {
1917

2018
public ItemDimDoor() {
21-
super(ModBlocks.DIMENSIONAL_DOOR, (ItemDoor) Items.IRON_DOOR);
19+
super(ModBlocks.DIMENSIONAL_DOOR);
2220
setUnlocalizedName(BlockDimDoorIron.ID);
2321
setRegistryName(new ResourceLocation(DimDoors.MODID, BlockDimDoorIron.ID));
2422
}
@@ -27,9 +25,4 @@ public ItemDimDoor() {
2725
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
2826
translateAndAdd("info.dimensional_door", tooltip);
2927
}
30-
31-
@Override
32-
protected BlockDimDoorBase getDoorBlock() {
33-
return ModBlocks.DIMENSIONAL_DOOR;
34-
}
3528
}

0 commit comments

Comments
 (0)