Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class LegacyFixesConfig {
public static boolean bedSpawnFix = true;
public static boolean doubleDoors = true;
public static boolean jumpClimbing = true;
public static boolean slideClimbing = false;
public static boolean keepXP = false;
Expand All @@ -16,6 +17,7 @@ public static void synchronizeConfiguration(File configFile) {
Configuration configuration = new Configuration(configFile);

bedSpawnFix = configuration.getBoolean("bedSpawnFix", Configuration.CATEGORY_GENERAL, bedSpawnFix, "Allows beds to set a player's spawn point during the day (as in 1.15+)");
doubleDoors = configuration.getBoolean("doubleDoors", Configuration.CATEGORY_GENERAL, doubleDoors, "Makes double doors open simultaneously");
jumpClimbing = configuration.getBoolean("jumpClimbing", Configuration.CATEGORY_GENERAL, jumpClimbing, "Allows climbing ladders by jumping (incompat with slideClimbing)");
slideClimbing = configuration.getBoolean("slideClimbing", Configuration.CATEGORY_GENERAL, slideClimbing, "Allows traversing ladders by looking up or down (incompat with jumpClimbing)");
keepXP = configuration.getBoolean("keepXP", Configuration.CATEGORY_GENERAL, keepXP, "Players keep their experience level / points on death");
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/cc/unilock/legacyfixes/module/DoubleDoorsModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Adapted from the Minecraft mod "copycore" by copygirl.
* <p/>
* Copyright (c) 2014 copygirl
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cc.unilock.legacyfixes.module;

import cc.unilock.legacyfixes.util.BlockLocation;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.BlockDoor;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

public class DoubleDoorsModule {
private static boolean handling = false;

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.world == null || event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || event.entityPlayer.isSneaking() || event.isCanceled() || event.getResult() == Event.Result.DENY || event.useBlock == Event.Result.DENY || handling) {
return;
}

handling = true;

BlockLocation loc = BlockLocation.get(event.world, event.x, event.y, event.z);

if (loc.getBlock() instanceof BlockDoor door) {
int direction = getDoorDirection(door, loc);
boolean isOpen = isDoorOpen(door, loc);
boolean isMirrored = isDoorMirrored(door, loc);

int i = (isMirrored ? -1 : 1);
switch (direction) {
case 0: loc = loc.relative(0, 0, i); break;
case 1: loc = loc.relative(-i, 0, 0); break;
case 2: loc = loc.relative(0, 0, -i); break;
case 3: loc = loc.relative( i, 0, 0); break;
}

if (loc.getBlock() == door && getDoorDirection(door, loc) == direction && isDoorOpen(door, loc) == isOpen && isDoorMirrored(door, loc) != isMirrored) {
door.onBlockActivated(loc.world, loc.x, loc.y, loc.z, event.entityPlayer, event.face, 0, 0,0);
}
}

handling = false;
}

private static int getDoorDirection(BlockDoor door, BlockLocation loc) {
return door.func_150013_e(loc.blockAccess, loc.x, loc.y, loc.z);
}

private static boolean isDoorOpen(BlockDoor door, BlockLocation loc) {
return door.func_150015_f(loc.blockAccess, loc.x, loc.y, loc.z);
}

private static boolean isDoorMirrored(BlockDoor door, BlockLocation loc) {
return (door.func_150012_g(loc.blockAccess, loc.x, loc.y, loc.z) & 16) != 0;
}
}
6 changes: 6 additions & 0 deletions src/main/java/cc/unilock/legacyfixes/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package cc.unilock.legacyfixes.proxy;

import cc.unilock.legacyfixes.LegacyFixesConfig;
import cc.unilock.legacyfixes.module.DoubleDoorsModule;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.common.MinecraftForge;

public class CommonProxy {
public void preInit(FMLPreInitializationEvent event) {
LegacyFixesConfig.synchronizeConfiguration(event.getSuggestedConfigurationFile());

if (LegacyFixesConfig.doubleDoors) {
MinecraftForge.EVENT_BUS.register(new DoubleDoorsModule());
}
//LegacyFixes.LOGGER.info("Initialized!");
}
}
195 changes: 195 additions & 0 deletions src/main/java/cc/unilock/legacyfixes/util/BlockLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* Borrowed from the Minecraft mod "copycore" by copygirl.
* <p/>
* Copyright (c) 2014 copygirl
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cc.unilock.legacyfixes.util;

import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockLocation {

/** The IBlockAccess for this block location. */
public final IBlockAccess blockAccess;
/** The World for this block location. <br>
* May be null if the IBlockAccess getter was used. */
public final World world;
/** The location for this block location. */
public final int x, y, z;

private final boolean isWorld;

private BlockLocation(IBlockAccess blockAccess, World world,
int x, int y, int z, boolean isWorld) {
this.blockAccess = blockAccess;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.isWorld = isWorld;
}

// Static instantiation methods

/** Returns a block location from this world and location. */
public static BlockLocation get(IBlockAccess blockAccess, int x, int y, int z) {
return new BlockLocation(blockAccess, null, x, y, z, false);
}
/** Returns a block location from this world and location. */
public static BlockLocation get(World world, int x, int y, int z) {
return new BlockLocation(world, world, x, y, z, true);
}
/** Returns a block location from the tile entity's location. */
public static BlockLocation get(TileEntity tileEntity) {
return get(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}

// Relative instantiation methods

/** Returns a block location with its location set relative to this one. */
public BlockLocation relative(int x, int y, int z) {
return new BlockLocation(blockAccess, world, this.x + x, this.y + y, this.z + z, isWorld);
}

/** Returns a block location for the block in this direction, this many blocks away. */
public BlockLocation offset(ForgeDirection direction, int distance) {
return relative(direction.offsetX * distance,
direction.offsetY * distance,
direction.offsetZ * distance);
}

/** Returns a block location for the neighbor block in this direction. */
public BlockLocation neighbor(ForgeDirection direction) {
return relative(direction.offsetX, direction.offsetY, direction.offsetZ);
}

/** Returns a block location for the block to the west (-X). */
public BlockLocation west() { return neighbor(ForgeDirection.WEST); }
/** Returns a block location for the block to the east (+X). */
public BlockLocation east() { return neighbor(ForgeDirection.EAST); }
/** Returns a block location for the block below (-Y). */
public BlockLocation below() { return neighbor(ForgeDirection.DOWN); }
/** Returns a block location for the block above (+Y). */
public BlockLocation above() { return neighbor(ForgeDirection.UP); }
/** Returns a block location for the block to the north (-Z). */
public BlockLocation north() { return neighbor(ForgeDirection.NORTH); }
/** Returns a block location for the block to the south (+Z). */
public BlockLocation south() { return neighbor(ForgeDirection.SOUTH); }

// Getting and setting

/** Gets the block at this location. */
public Block getBlock() { return blockAccess.getBlock(x, y, z); }
/** Gets the metadata for the block at this location. */
public int getMetadata() { return blockAccess.getBlockMetadata(x, y, z); }
/** Gets the tile entity of the block at this location. */
public TileEntity getTileEntity() { return blockAccess.getTileEntity(x, y, z); }

/** Gets the tile entity of the block at this location.
* Returns null if the tile entity is not the correct type. */
public <T extends TileEntity> T getTileEntity(Class<T> tileEntityClass) {
TileEntity tileEntity = getTileEntity();
return (tileEntityClass.isInstance(tileEntity) ? (T)tileEntity : null);
}

/** Gets the tile entity of the block at this location.
* Throws an error if there is no tile entity or it's not the correct type. */
public <T extends TileEntity> T getTileEntityStrict(Class<T> tileEntityClass) {
TileEntity tileEntity = getTileEntity();
if (tileEntity == null)
throw new Error(String.format("Expected tile entity at %s, but none found.", this));
if (!tileEntityClass.isInstance(tileEntity))
throw new Error(String.format("Expected tile entity at %s to be '%s', but found '%s' instead.",
this, tileEntityClass.getName(), tileEntity.getClass().getName()));
return (T)tileEntity;
}

/** Sets the block at this location. */
public void setBlock(Block block) {
if (isWorld) world.setBlock(x, y, z, block);
}
/** Sets the metadata for the block at this location. */
public void setMetadata(int metadata) {
if (isWorld) world.setBlockMetadataWithNotify(x, y, z, metadata, SetBlockFlag.DEFAULT);
}
/** Sets the block and its metadata at this location. */
public void setBlockAndMetadata(Block block, int metadata) {
if (isWorld) world.setBlock(x, y, z, block, metadata, SetBlockFlag.DEFAULT);
}

/** Sets the tile entity for the block at this location. <br>
* <b>Warning:</b> This is usually done automatically.
* Only use this when you know what you're doing! */
public void setTileEntity(TileEntity tileEntity) {
if (isWorld) world.setTileEntity(x, y, z, tileEntity);
}

// Additional block related methods

/** Returns if the block is air. */
public boolean isAir() {
return blockAccess.isAirBlock(x, y, z);
}
/** Returns if the block is replaceable, like tall grass or fluids. */
public boolean isReplaceable() {
return getBlock().isReplaceable(blockAccess, x, y, z);
}
/** Returns if the block is solid on that side. */
public boolean isSideSolid(ForgeDirection side) {
return blockAccess.isSideSolid(x, y, z, side, false);
}

// Additional tile entity related methods



// Equals, hashCode and toString

@Override
public boolean equals(Object obj) {
BlockLocation loc;
return ((obj instanceof BlockLocation) &&
(blockAccess == (loc = (BlockLocation)obj).blockAccess) &&
(x == loc.x) && (y == loc.y) && (z == loc.z));
}

@Override
public int hashCode() {
return (blockAccess.hashCode() ^ x ^ (z << 4) ^ (y << 8));
}

@Override
public String toString() {
return String.format("[%s; Coords=%s,%s,%s]", getWorldName(), x, y, z);
}

// Helper functions

private String getWorldName() {
return (isWorld ? ("DIM=" + Integer.toString(world.provider.dimensionId))
: blockAccess.toString());
}

}
41 changes: 41 additions & 0 deletions src/main/java/cc/unilock/legacyfixes/util/SetBlockFlag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Borrowed from the Minecraft mod "copycore" by copygirl.
* <p/>
* Copyright (c) 2014 copygirl
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cc.unilock.legacyfixes.util;

public final class SetBlockFlag {

/** When set, causes a block update to the surrounding blocks. */
public static final int BLOCK_UPDATE = 0x1;
/** When set on server, sends the block change to the client. */
public static final int SEND_TO_CLIENT = 0x2;
/** When set on client, will not render the chunk again. */
public static final int DONT_RERENDER = 0x4;

/** The default setting, will cause a block
* update and send the change to the client. */
public static final int DEFAULT = BLOCK_UPDATE | SEND_TO_CLIENT;

private SetBlockFlag() { }

}

0 comments on commit 7d3912c

Please sign in to comment.