Refactor utils

This commit is contained in:
Runemoro 2017-12-21 20:29:37 -05:00
parent bc9c663741
commit 02c7c61c73
58 changed files with 395 additions and 446 deletions

View file

@ -75,6 +75,7 @@ processResources {
task generatePocketSchematics(dependsOn: jar, type: JavaExec, group: "dimdoors") {
classpath = files('build/libs/dimdoors.jar')
classpath += sourceSets.main.runtimeClasspath
main = "com.zixiken.dimdoors.shared.util.PocketSchematicGenerator"
main = "com.zixiken.dimdoors.shared.tools.PocketSchematicGenerator"
//noinspection GroovyAssignabilityCheck (IntelliJ is wrong)
args "src/main/resources/assets/dimdoors/pockets/schematic"
}

View file

@ -1,6 +1,6 @@
package com.zixiken.dimdoors;
import com.zixiken.dimdoors.shared.commands.PocketCommand;
import com.zixiken.dimdoors.shared.commands.CommandPocket;
import com.zixiken.dimdoors.shared.commands.CommandDimTeleport;
import com.zixiken.dimdoors.shared.DDConfig;
import com.zixiken.dimdoors.shared.DDProxyCommon;
@ -72,7 +72,7 @@ public class DimDoors {
private void registerCommands(FMLServerStartingEvent event) {
event.registerServerCommand(new CommandDimTeleport());
event.registerServerCommand(new PocketCommand());
event.registerServerCommand(new CommandPocket());
}
public static boolean isClient() {

View file

@ -2,7 +2,6 @@ package com.zixiken.dimdoors.client;
import com.zixiken.dimdoors.shared.DDProxyCommon;
import com.zixiken.dimdoors.shared.entities.EntityMonolith;
import com.zixiken.dimdoors.shared.entities.RenderMonolith;
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
import net.minecraft.client.Minecraft;

View file

@ -1,7 +1,8 @@
package com.zixiken.dimdoors.shared.entities;
package com.zixiken.dimdoors.client;
import java.util.Random;
import com.zixiken.dimdoors.shared.entities.EntityMonolith;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
@ -21,14 +22,14 @@ public class ModelMonolith extends ModelBase {
textureHeight = 256;
wholeMonolith = new ModelRenderer(this, 0, 0);
wholeMonolith.addBox(-24F,-108F/1.3F, -6F, 48, 108, 12);
wholeMonolith.addBox(-24F, -108F / 1.3F, -6F, 48, 108, 12);
}
@Override
public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
EntityMonolith monolith = (EntityMonolith) entityIn;
setRotationAngles(0, 0, 0, 0, 0,0, monolith);
setRotationAngles(0, 0, 0, 0, 0, 0, monolith);
GL11.glScalef(monolith.getRenderSizeModifier(), monolith.getRenderSizeModifier(), monolith.getRenderSizeModifier());
wholeMonolith.render(scale);
}

View file

@ -1,6 +1,6 @@
package com.zixiken.dimdoors.client;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.client.particle.ParticleSimpleAnimated;
import net.minecraft.client.renderer.BufferBuilder;

View file

@ -1,6 +1,8 @@
package com.zixiken.dimdoors.shared.entities;
package com.zixiken.dimdoors.client;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.ModelMonolith;
import com.zixiken.dimdoors.shared.entities.EntityMonolith;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.entity.RenderLiving;

View file

@ -7,7 +7,7 @@ import java.util.Random;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
import com.zixiken.dimdoors.shared.util.RGBA;
import ddutils.render.RGBA;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.vertex.*;
import net.minecraft.util.EnumFacing;

View file

@ -9,8 +9,6 @@ import com.zixiken.dimdoors.shared.tileentities.*;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import com.zixiken.dimdoors.shared.world.ModBiomes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldProvider;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

View file

@ -30,8 +30,8 @@ public class EventHandler {
@SubscribeEvent(priority = EventPriority.LOWEST) // don't let other mods do something based on the event
public static void onLivingHurt(LivingHurtEvent event) {
Entity entity = event.getEntity();
if (entity.dimension == DimDoorDimensions.LIMBO.getId() && event.getSource() == DamageSource.FALL) {
event.setCanceled(true);// no fall damage in LIMBO
if (entity.dimension == DimDoorDimensions.limbo.getId() && event.getSource() == DamageSource.FALL) {
event.setCanceled(true);// no fall damage in limbo
}
}

View file

@ -1,8 +1,8 @@
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.shared.pockets.PocketTemplate;
import com.zixiken.dimdoors.shared.util.MathUtils;
import com.zixiken.dimdoors.shared.util.Schematic;
import ddutils.math.MathUtils;
import ddutils.schem.Schematic;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -22,13 +22,12 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.zixiken.dimdoors.shared.util.SchematicConverter;
import com.zixiken.dimdoors.shared.tools.SchematicConverter;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompressedStreamTools;
import org.apache.commons.io.IOUtils;
/**
*
* @author Robijnvogel
*/
public class SchematicHandler { // TODO: make this more general (not dimdoors-related)
@ -134,7 +133,7 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
if (!schematicNBT.hasKey("Version")) {
schematic = SchematicConverter.loadOldDimDoorSchematicFromNBT(schematicNBT, template.getName());
schematic = SchematicConverter.convertSchematic(schematicNBT, template.getName());
} else {
schematic = Schematic.loadFromNBT(schematicNBT, template.getName());
}
@ -151,7 +150,7 @@ 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.width > (template.getSize() + 1) * 16 || schematic.length > (template.getSize() + 1) * 16)) {
schematic = null;
DimDoors.log.warn("Schematic " + template.getName() + " was bigger than specified in its json file and therefore wasn't loaded");
}
@ -235,7 +234,6 @@ public class SchematicHandler { // TODO: make this more general (not dimdoors-re
return templates.get(index);
}
/**
* Gets a random template matching certain criteria.
*

View file

@ -1,30 +1,39 @@
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.pockets.Pocket;
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
import ddutils.Location;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.ToString;
import lombok.Value;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import java.util.Random;
@Value @ToString @AllArgsConstructor @Builder(toBuilder = true)
public class VirtualLocation { // TODO: use BlockPos/Location
int dimID;
int x;
int y;
int z;
Location location;
int depth;
public NBTTagCompound writeToNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("dim", dimID);
nbt.setInteger("x", x);
nbt.setInteger("y", y);
nbt.setInteger("z", z);
nbt.setInteger("depth", depth);
return nbt;
public VirtualLocation(int dim, BlockPos pos, int depth) {
this(new Location(dim, pos), depth);
}
public VirtualLocation(int dim, int x, int y, int z, int depth) {
this(new Location(dim, x, y, z), depth);
}
public int getDim() { return location.getDim(); }
public BlockPos getPos() { return location.getPos(); }
public int getX() { return location.getX(); }
public int getY() { return location.getY(); }
public int getZ() { return location.getZ(); }
public static VirtualLocation readFromNBT(NBTTagCompound nbt) {
int dim = nbt.getInteger("dim");
int x = nbt.getInteger("x");
@ -34,7 +43,44 @@ public class VirtualLocation { // TODO: use BlockPos/Location
return new VirtualLocation(dim, x, y, z, depth);
}
public Location getOverworldLocation() {
return new Location(dimID, x, y, z);
public NBTTagCompound writeToNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("dim", location.getDim());
nbt.setInteger("x", location.getPos().getX());
nbt.setInteger("y", location.getPos().getY());
nbt.setInteger("z", location.getPos().getZ());
nbt.setInteger("depth", depth);
return nbt;
}
// TODO: move to VirtualLocation
public static VirtualLocation fromLocation(Location location) { // TODO: reverse function too
VirtualLocation virtualLocation = null;
if (DimDoorDimensions.isPocketDimension(location.getDim())) {
Pocket pocket = PocketRegistry.getForDim(location.getDim()).getPocketFromLocation(location.getPos().getY(), location.getPos().getY(), location.getPos().getZ());
if (pocket != null) {
virtualLocation = pocket.getVirtualLocation();
} else {
virtualLocation = new VirtualLocation(0, 0, 0, 0, 0); // TODO: door was placed in a pocket dim but outside of a pocket...
}
}
if (virtualLocation == null) {
virtualLocation = new VirtualLocation(WorldUtils.getDim(location.getWorld()), location.getPos().getX(), location.getPos().getY(), location.getPos().getZ(), 0);
}
return virtualLocation;
}
public VirtualLocation transformDepth(int depth) { // TODO: Config option for block ratio between depths (see video of removed features)
Random random = new Random();
int depthDiff = Math.abs(this.depth - depth);
int base = DDConfig.getOwCoordinateOffsetBase();
double power = DDConfig.getOwCoordinateOffsetPower();
int xOffset = random.nextInt((int) Math.pow(base * depthDiff, power)) * (random.nextBoolean() ? 1 : -1);
int zOffset = random.nextInt((int) Math.pow(base * depthDiff, power)) * (random.nextBoolean() ? 1 : -1);
return new VirtualLocation(getDim(), getPos().offset(EnumFacing.EAST, xOffset).offset(EnumFacing.SOUTH, zOffset), depth);
}
public Location projectToWorld() {
return transformDepth(0).getLocation();
}
}

View file

@ -10,8 +10,8 @@ import com.zixiken.dimdoors.shared.rifts.RiftRegistry;
import com.zixiken.dimdoors.shared.tileentities.TileEntityEntranceRift;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.Location;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;

View file

@ -6,11 +6,11 @@ import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.util.ResourceLocation;
public class BlockDimTrapdoorWood extends BlockDimensionalTrapdoor {
public class BlockDimensionalTrapdoorWood extends BlockDimensionalTrapdoor {
public static final String ID = "dimensional_trapdoor";
public BlockDimTrapdoorWood() {
public BlockDimensionalTrapdoorWood() {
super(Material.WOOD);
setRegistryName(new ResourceLocation(DimDoors.MODID, ID));
setUnlocalizedName(ID);

View file

@ -3,10 +3,9 @@ package com.zixiken.dimdoors.shared.blocks;
import java.util.Random;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.DDConfig;
import com.zixiken.dimdoors.shared.util.RandomUtils;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import com.zixiken.dimdoors.shared.VirtualLocation;
import ddutils.Location;
import ddutils.TeleportUtils;
import com.zixiken.dimdoors.shared.world.limbodimension.LimboDecay;
import com.zixiken.dimdoors.shared.world.limbodimension.WorldProviderLimbo;
import lombok.Getter;
@ -175,15 +174,13 @@ public class BlockFabric extends Block {
}
@Override
public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn) {
IBlockState state = worldIn.getBlockState(pos);
if (state.getValue(TYPE) == EnumType.ETERNAL && worldIn.provider instanceof WorldProviderLimbo && entityIn instanceof EntityPlayer) {
Location origLocation = new Location(worldIn, pos);
Location transFormedLocation = RandomUtils.transformLocationRandomly(DDConfig.getOwCoordinateOffsetBase(), DDConfig.getOwCoordinateOffsetPower(), DDConfig.getMaxDungeonDepth(), origLocation);
BlockPos correctedPos = DimDoors.proxy.getWorldServer(0).getTopSolidOrLiquidBlock(transFormedLocation.getPos());
Location correctedLocation = new Location(0, correctedPos);
TeleportUtils.teleport(entityIn, correctedLocation, 0, 0);
public void onEntityWalk(World world, BlockPos pos, Entity entityIn) {
IBlockState state = world.getBlockState(pos);
if (state.getValue(TYPE) == EnumType.ETERNAL && world.provider instanceof WorldProviderLimbo && entityIn instanceof EntityPlayer) {
Location loc = VirtualLocation.fromLocation(new Location(world, pos)).projectToWorld();
BlockPos correctedPos = loc.getWorld().getTopSolidOrLiquidBlock(loc.getPos());
Random random = new Random();
TeleportUtils.teleport(entityIn, new Location(loc.getDim(), correctedPos), random.nextFloat() * 360, random.nextFloat() * 360);
}
}

View file

@ -6,6 +6,7 @@ import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.ParticleRiftEffect;
import com.zixiken.dimdoors.shared.items.ModItems;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
import ddutils.blocks.BlockSpecialAir;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.state.IBlockState;

View file

@ -1,9 +1,9 @@
package com.zixiken.dimdoors.shared.blocks;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
import com.zixiken.dimdoors.shared.VirtualLocation;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import ddutils.Location;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
@ -25,7 +25,7 @@ public interface IRiftProvider<T extends TileEntityRift> extends ITileEntityProv
T rift = createNewTileEntity(world, state.getBlock().getMetaFromState(state));
// Set the rift's virtual position
rift.setVirtualLocation(PocketRegistry.locationToVirtualLocation(new Location(rift.getWorld(), rift.getPos())));
rift.setVirtualLocation(VirtualLocation.fromLocation(new Location(rift.getWorld(), rift.getPos())));
// Configure the rift to its default functionality
setupRift(rift);

View file

@ -17,7 +17,7 @@ public class ModBlocks {
public static final BlockDimensionalDoorUnstable UNSTABLE_DIMENSIONAL_DOOR = new BlockDimensionalDoorUnstable();
public static final BlockDimensionalDoorTransient TRANSIENT_DIMENSIONAL_DOOR = new BlockDimensionalDoorTransient();
public static final BlockDimensionalDoorWarp WARP_DIMENSIONAL_DOOR = new BlockDimensionalDoorWarp();
public static final BlockDimTrapdoorWood DIMENSIONAL_TRAPDOOR = new BlockDimTrapdoorWood();
public static final BlockDimensionalTrapdoorWood DIMENSIONAL_TRAPDOOR = new BlockDimensionalTrapdoorWood();
// Blocks
public static final BlockFabric FABRIC = new BlockFabric();

View file

@ -1,13 +1,13 @@
package com.zixiken.dimdoors.shared.commands;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.StringUtils;
import ddutils.Location;
import ddutils.StringUtils;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import ddutils.TeleportUtils;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;

View file

@ -4,10 +4,10 @@ import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.*;
import com.zixiken.dimdoors.shared.pockets.*;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.StringUtils;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.Location;
import ddutils.StringUtils;
import ddutils.TeleportUtils;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
@ -21,11 +21,11 @@ import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PocketCommand extends CommandBase {
public class CommandPocket extends CommandBase {
private final List<String> aliases;
public PocketCommand() {
public CommandPocket() {
aliases = new ArrayList<>();
aliases.add("pocket");
}

View file

@ -2,8 +2,8 @@ package com.zixiken.dimdoors.shared.entities;
import com.zixiken.dimdoors.shared.sound.ModSounds;
import com.zixiken.dimdoors.shared.DDConfig;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import ddutils.Location;
import ddutils.TeleportUtils;
import com.zixiken.dimdoors.shared.world.limbodimension.WorldProviderLimbo;
import com.zixiken.dimdoors.shared.world.pocketdimension.WorldProviderDungeonPocket;
import com.zixiken.dimdoors.shared.world.pocketdimension.WorldProviderPublicPocket;
@ -51,16 +51,13 @@ public class EntityMonolith extends EntityFlying implements IMob {
setSize(WIDTH, HEIGHT);
noClip = true;
aggroCap = MathHelper.getInt(rand, MIN_AGGRO_CAP, MAX_AGGRO_CAP);
setEntityInvulnerable(true);
}
public boolean isDangerous() {
return DDConfig.isMonolithTeleportationEnabled() && (world.provider instanceof WorldProviderLimbo || DDConfig.isDangerousLimboMonolithsEnabled());
}
@Override
protected void damageEntity(DamageSource damageSrc, float damageAmount) {
}
@Override
public boolean attackEntityFrom(DamageSource source, float amount) {
if (source != DamageSource.IN_WALL) {
@ -119,7 +116,7 @@ public class EntityMonolith extends EntityFlying implements IMob {
@Override
public void onEntityUpdate() {
// Remove this Monolith if it's not in Limbo or in a pocket dungeon TODO: any pocket dim?
// Remove this Monolith if it's not in Limbo or in a pocket dungeon
if (!(world.provider instanceof WorldProviderLimbo || world.provider instanceof WorldProviderDungeonPocket)) {
setDead();
super.onEntityUpdate();
@ -154,7 +151,7 @@ public class EntityMonolith extends EntityFlying implements IMob {
// Teleport the target player if various conditions are met
if (aggro >= MAX_AGGRO && !world.isRemote && DDConfig.isMonolithTeleportationEnabled() && !player.capabilities.isCreativeMode && isDangerous()) {
aggro = 0;
Location destination = WorldProviderLimbo.getLimboSkySpawn(player); // TODO: teleportToLimbo method
Location destination = WorldProviderLimbo.getLimboSkySpawn(player);
TeleportUtils.teleport(player, destination, 0, 0);
player.world.playSound(player, player.getPosition(), ModSounds.CRACK, SoundCategory.HOSTILE, 13, 1);
}

View file

@ -2,9 +2,9 @@ package com.zixiken.dimdoors.shared.items;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
import com.zixiken.dimdoors.shared.util.Location;
import ddutils.Location;
import com.zixiken.dimdoors.shared.RayTraceHelper;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import ddutils.TeleportUtils;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

View file

@ -4,11 +4,11 @@ import com.zixiken.dimdoors.shared.VirtualLocation;
import com.zixiken.dimdoors.shared.rifts.RiftDestination;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.rifts.WeightedRiftDestination;
import com.zixiken.dimdoors.shared.util.Location;
import ddutils.Location;
import java.util.*;
import com.zixiken.dimdoors.shared.util.MathUtils;
import ddutils.math.MathUtils;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.entity.player.EntityPlayer;

View file

@ -36,7 +36,7 @@ public class PocketGenerator {
*/
public Pocket generateDungeonPocket(VirtualLocation virtualLocation) {
int depth = virtualLocation.getDepth();
float netherProbability = virtualLocation.getDimID() == -1 ? 1 : (float) depth / 50; // TODO: improve nether probability
float netherProbability = virtualLocation.getDim() == -1 ? 1 : (float) depth / 50; // TODO: improve nether probability
Random random = new Random();
String group = random.nextFloat() < netherProbability ? "nether" : "ruins";
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, DDConfig.getMaxPocketSize(), false);

View file

@ -1,11 +1,11 @@
package com.zixiken.dimdoors.shared.pockets;
import com.zixiken.dimdoors.shared.DDConfig;
import com.zixiken.dimdoors.shared.VirtualLocation;
import com.zixiken.dimdoors.shared.util.Location;
import ddutils.math.GridUtils;
import ddutils.Location;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.util.NBTUtils;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.nbt.NBTUtils;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import java.util.HashMap;
@ -248,21 +248,4 @@ public class PocketRegistry extends WorldSavedData {
return pocket.isPlayerAllowedInPocket(player) && pocket.isLocationWithinPocketBounds(x, y, z, gridSize);
}
}
// TODO: move to VirtualLocation
public static VirtualLocation locationToVirtualLocation(Location location) { // TODO: reverse function too
VirtualLocation virtualLocation = null;
if (DimDoorDimensions.isPocketDimension(location.getDimID())) {
Pocket pocket = PocketRegistry.getForDim(location.getDimID()).getPocketFromLocation(location.getPos().getY(), location.getPos().getY(), location.getPos().getZ());
if (pocket != null) {
virtualLocation = pocket.getVirtualLocation();
} else {
virtualLocation = new VirtualLocation(0, 0, 0, 0, 0); // TODO: door was placed in a pocket dim but outside of a pocket...
}
}
if (virtualLocation == null) {
virtualLocation = new VirtualLocation(WorldUtils.getDim(location.getWorld()), location.getPos().getX(), location.getPos().getY(), location.getPos().getZ(), 0);
}
return virtualLocation;
}
}

View file

@ -1,8 +1,8 @@
package com.zixiken.dimdoors.shared.pockets;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.Schematic;
import ddutils.Location;
import ddutils.schem.Schematic;
import com.zixiken.dimdoors.DimDoors;
import java.util.ArrayList;
@ -44,7 +44,7 @@ public class PocketTemplate {
int dimID = pocket.dimID;
int xBase = pocket.getX() * gridSize * 16;
int zBase = pocket.getZ() * gridSize * 16;
DimDoors.log.info("Placing new pocket using schematic " + schematic.getSchematicName() + " at x = " + xBase + ", z = " + zBase);
DimDoors.log.info("Placing new pocket using schematic " + schematic.schematicName + " at x = " + xBase + ", z = " + zBase);
WorldServer world = DimDoors.proxy.getWorldServer(dimID);
DimDoors.disableRiftSetup = true;
@ -53,7 +53,7 @@ public class PocketTemplate {
// Set pocket riftLocations
pocket.riftLocations = new ArrayList<>();
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
BlockPos pos = new BlockPos(
xBase + tileEntityNBT.getInteger("x"),
yBase + tileEntityNBT.getInteger("y"),

View file

@ -1,8 +1,8 @@
package com.zixiken.dimdoors.shared.rifts;
import com.zixiken.dimdoors.shared.util.INBTStorable;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.NBTUtils;
import ddutils.nbt.INBTStorable;
import ddutils.Location;
import ddutils.nbt.NBTUtils;
import lombok.*;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
@ -14,13 +14,14 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("EmptyMethod")
@Getter @ToString @EqualsAndHashCode @AllArgsConstructor(access = AccessLevel.PRIVATE)
public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix lombok and make this abstract
@Getter private EnumType type;
@Getter protected RiftDestination oldDestination;
public enum EnumType {
RELATIVE, LOCAL, GLOBAL, NEW_PUBLIC, PRIVATE, LIMBO, AVAILABLE_LINK, POCKET_ENTRANCE, POCKET_EXIT, PRIVATE_POCKET_EXIT, ESCAPE;
RELATIVE, LOCAL, GLOBAL, NEW_PUBLIC, PRIVATE, LIMBO, AVAILABLE_LINK, POCKET_ENTRANCE, POCKET_EXIT, PRIVATE_POCKET_EXIT, ESCAPE
}
private RiftDestination() {
@ -188,7 +189,7 @@ public /*abstract*/ class RiftDestination implements INBTStorable { // TODO: fix
public static class GlobalDestination extends RiftDestination { // TODO: location directly in nbt like minecraft?
private Location loc;
private GlobalDestination() {};
private GlobalDestination() {}
@Override
public void readFromNBT(NBTTagCompound nbt) {

View file

@ -3,9 +3,9 @@ package com.zixiken.dimdoors.shared.rifts;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.VirtualLocation;
import com.zixiken.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo;
import com.zixiken.dimdoors.shared.util.INBTStorable;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.nbt.INBTStorable;
import ddutils.Location;
import ddutils.WorldUtils;
import lombok.*;
import lombok.experimental.Wither;
import net.minecraft.nbt.NBTBase;
@ -31,7 +31,7 @@ public class RiftRegistry extends WorldSavedData {
private World world;
@lombok.AllArgsConstructor @lombok.EqualsAndHashCode @lombok.Builder(toBuilder = true)
public static class RiftInfo implements com.zixiken.dimdoors.shared.util.INBTStorable {
public static class RiftInfo implements ddutils.nbt.INBTStorable {
@Builder.Default @Getter private Set<AvailableLinkInfo> availableLinks = new HashSet<>(); // ignore intellij warnings, builder needs these
@Builder.Default @Getter private Set<Location> sources = new HashSet<>();
@Builder.Default @Getter private Set<Location> destinations = new HashSet<>();
@ -133,7 +133,7 @@ public class RiftRegistry extends WorldSavedData {
}
public void initNewRegistry() {
// TODO
}
@Override
@ -304,7 +304,7 @@ public class RiftRegistry extends WorldSavedData {
}
public static RiftRegistry getRegistry(Location rift) {
return getForDim(rift.getDimID());
return getForDim(rift.getDim());
}
public Location getPrivatePocketEntrance(String playerUUID) {

View file

@ -7,10 +7,10 @@ import com.zixiken.dimdoors.shared.pockets.PocketGenerator;
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
import com.zixiken.dimdoors.shared.rifts.RiftDestination.*;
import com.zixiken.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.MathUtils;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.Location;
import ddutils.math.MathUtils;
import ddutils.TeleportUtils;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import lombok.Getter;
import net.minecraft.block.state.IBlockState;
@ -325,7 +325,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
}
if (destLoc == null) {
if (entity instanceof EntityPlayer) DimDoors.chat((EntityPlayer) entity, "You tried to escape a pocket or leave your private pocket, but you teleported into it!");
return false; // TODO: LIMBO?
return false; // TODO: limbo?
}
} else {
return false; // Non-player/owned entity tried to escape/leave private pocket
@ -424,7 +424,7 @@ public abstract class TileEntityRift extends TileEntity implements ITickable { /
private void makeDestinationPermanent(WeightedRiftDestination weightedDestination, Location destLoc) {
riftStateChanged = true;
RiftDestination newDest;
if (WorldUtils.getDim(world) == destLoc.getDimID()) {
if (WorldUtils.getDim(world) == destLoc.getDim()) {
newDest = new LocalDestination(destLoc.getPos()); // TODO: RelativeDestination instead?
} else {
newDest = new GlobalDestination(destLoc);

View file

@ -1,6 +1,6 @@
package com.zixiken.dimdoors.shared.rifts;
import com.zixiken.dimdoors.shared.util.INBTStorable;
import ddutils.nbt.INBTStorable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

View file

@ -2,10 +2,10 @@ package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.shared.pockets.PocketRegistry;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.RGBA;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import ddutils.Location;
import ddutils.render.RGBA;
import ddutils.TeleportUtils;
import ddutils.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import lombok.Getter;
import net.minecraft.entity.Entity;

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.util;
package com.zixiken.dimdoors.shared.tools;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.server.DDProxyServer;
@ -7,6 +7,7 @@ import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import com.zixiken.dimdoors.shared.rifts.RiftDestination;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.rifts.WeightedRiftDestination;
import ddutils.schem.Schematic;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.state.IBlockState;
@ -21,6 +22,7 @@ import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.registries.GameData;
import net.minecraftforge.registries.RegistryManager;
import ddutils.math.MathUtils;
import java.io.DataOutputStream;
import java.io.File;
@ -32,7 +34,6 @@ import java.util.Collections;
import java.util.List;
/**
*
* @author Robijnvogel
*/
public class PocketSchematicGenerator {

View file

@ -1,7 +1,9 @@
package com.zixiken.dimdoors.shared.util;
package com.zixiken.dimdoors.shared.tools;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.blocks.BlockFabric;
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import ddutils.schem.Schematic;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
@ -13,60 +15,47 @@ import java.util.HashMap;
import java.util.Map;
/**
*
* @author Robijnvogel
*/
public class SchematicConverter {
private static final String[] OLDDIMDOORBLOCKNAMES = {
"Dimensional Door",
"Fabric of Reality",
"transientDoor", //only used in the two old Overworld gateway (worldgen) structures
"Warp Door"};
private static final String[] NEWDIMDOORBLOCKNAMES = {
"dimensional_door",
"fabric", //[type=fabric] is the default blockstate
"transient_dimensional_door",
"warp_dimensional_door"};
private static final Map<String, IBlockState> stateMap = new HashMap<>();
static {
stateMap.put("dimdoors:Dimensional Door", ModBlocks.DIMENSIONAL_DOOR.getDefaultState());
stateMap.put("dimdoors:Fabric of Reality", ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.REALITY));
stateMap.put("dimdoors:Fabric of RealityPerm", ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.ANCIENT));
stateMap.put("dimdoors:transientDoor", ModBlocks.TRANSIENT_DIMENSIONAL_DOOR.getDefaultState());
stateMap.put("dimdoors:Warp Door", ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState());
}
public static Schematic loadOldDimDoorSchematicFromNBT(NBTTagCompound nbt, String parName) { //@todo, maybe make this a separate class, so values can be final so they HAVE TO be set in a newly designed constructor?
public static Schematic convertSchematic(NBTTagCompound nbt, String name) { //@todo, maybe make this a separate class, so values can be final so they HAVE TO be set in a newly designed constructor?
Schematic schematic = new Schematic();
//schematic.version = 1; //already the default value
//schematic.author = "DimDoors"; //already the default value
schematic.schematicName = parName.equals("") ? "Auto-converted-DimDoors-for-MC-1.7.10-schematic" : parName;
schematic.version = 1; //already the default value
schematic.author = "DimDoors"; // TODO: didn't the old schematics have an author?
schematic.schematicName = name.equals("") ? "Unknown" : name;
schematic.creationDate = System.currentTimeMillis();
schematic.requiredMods = new String[]{DimDoors.MODID};
schematic.width = nbt.getShort("Width");
schematic.height = nbt.getShort("Height");
schematic.length = nbt.getShort("Length");
//schematic.offset = new int[]{0, 0, 0}; //already the default value
schematic.offset = new int[]{0, 0, 0}; // TODO: center them
byte[] blockIntArray = nbt.getByteArray("Blocks");
if (nbt.hasKey("Palette")) {
NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette");
for (int i = 0; i < paletteNBT.tagCount(); i++) {
//DimDoors.log.info("reading pallete from schematic... i = " + i);
String blockString = paletteNBT.getStringTagAt(i);
boolean isAncientFabric = false;
if (blockString.startsWith("dimdoors")) {
String dimdoorsBlockName = blockString.split(":")[1];
if (dimdoorsBlockName.equals("Fabric of RealityPerm")) { //only special case, because this is now another state of another block
isAncientFabric = true;
} else {
dimdoorsBlockName = convertOldDimDoorsBlockNameToNewDimDoorsBlockName(dimdoorsBlockName);
blockString = "dimdoors:" + dimdoorsBlockName;
}
}
IBlockState blockstate;
if (!isAncientFabric) {
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockString));
blockstate = block.getDefaultState();
// Get the correct block state
if (blockString.startsWith("dimdoors")) {
blockstate = stateMap.get(blockString);
} else {
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("dimdoors:FABRIC"));
blockstate = Schematic.getBlockStateWithProperties(block, new String[]{"type=ancient"});
blockstate = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockString)).getDefaultState();
}
schematic.pallette.add(blockstate);
}
} else {
@ -97,7 +86,7 @@ public class SchematicConverter {
block = ModBlocks.TRANSIENT_DIMENSIONAL_DOOR;
break;
}
//if (id != 0 && block.getRegistryName().toString().equals("minecraft:air")) throw new RuntimeException("Change conversion code!");
if (id != 0 && block.getRegistryName().toString().equals("minecraft:air")) throw new RuntimeException("Change conversion code!");
schematic.pallette.add(block.getDefaultState());
palletteMap.put(id, currentPalletteIndex);
blockIntArray[i] = currentPalletteIndex;
@ -116,7 +105,7 @@ public class SchematicConverter {
IBlockState baseState = schematic.pallette.get(blockInt); //this is the default blockstate except for ancient fabric
if (baseState == baseState.getBlock().getDefaultState()) { //should only be false if {@code baseState} is ancient fabric
IBlockState additionalState = baseState.getBlock().getStateFromMeta(metadata); // TODO: this was getStateFromMeta(metadata), but that method got deprecated and just calls getDefaultState(). Is this right?
IBlockState additionalState = baseState.getBlock().getStateFromMeta(metadata);
if (schematic.pallette.contains(additionalState)) { //check whether or not this blockstate is already in the list
blockInt = schematic.pallette.indexOf(additionalState);
} else {
@ -124,7 +113,7 @@ public class SchematicConverter {
// DimDoors.log.info("New blockstate detected. Original blockInt = " + blockInt + " and baseState is " + baseState);
blockInt = schematic.pallette.size() - 1;
}
} else { //if this is ancient fabric
} else { // if this is 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);
}
@ -142,23 +131,4 @@ public class SchematicConverter {
return schematic;
}
private static String convertOldDimDoorsBlockNameToNewDimDoorsBlockName(String dimdoorsBlockName) {
if (OLDDIMDOORBLOCKNAMES.length != NEWDIMDOORBLOCKNAMES.length) {
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;
}
int i = 0;
for (; i < OLDDIMDOORBLOCKNAMES.length; i++) {
if (OLDDIMDOORBLOCKNAMES[i].equals(dimdoorsBlockName)) {
return NEWDIMDOORBLOCKNAMES[i];
} else {
if (i == OLDDIMDOORBLOCKNAMES.length - 1) {
DimDoors.log.warn(dimdoorsBlockName + " as an old dimdoors block name is unknown.");
}
}
}
return null;
}
}

View file

@ -1,84 +0,0 @@
package com.zixiken.dimdoors.shared.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
*
* @author Robijnvogel
*/
public class MathUtils {
/**
* Compares the integers in two arrays and returns true if any integer in
* the first set is within range 0 to {@code difference} - 1 of any integer
* in the second array.
*
* @param setOne the first integer array to compare
* @param difference see method description
* @param setTwo the second integer array to compare
* @pre difference >= 0
* @throws IllegalArgumentException if precondition is violated
* @return {@code (\exists i, j; ; abs(setOne[i] - setTwo[j]) < difference }
*/
public static boolean withinDistanceOf(int[] setOne, int difference, int[] setTwo) throws IllegalArgumentException {
if (difference < 0) {
throw new IllegalArgumentException("precondition was violated");
}
for (int one : setOne) {
for (int two : setTwo) {
if (Math.max(one, two) - Math.min(one, two) < difference) {
return true;
}
}
}
return false;
}
/**
* Returns the sum of the values of all integer elements in an integer array
*
* @param intArray the integers to calculate the sum of
* @param flag this flag is meant to check if all elements in the array must
* be positive (0), negative(1), or it doesn't matter (anything else)
* @pre
* {@code (flag != 0 && flag != 1) || (flag == 0 && (\forall i; intArray.has(i); i >= 0)) || (flag == 1 && (\forall i; intArray.has(i); i <= 0))}
* @throws IllegalArgumentException if precondition is violated
* @return {@code sum(i = 0; intArray.has(i); intArray[i]) }
*/
public static int arraySum(int[] intArray, short flag) {
int r = 0;
for (int i : intArray) { //check flag
if (flag == 0 && i < 0) {
throw new IllegalArgumentException("all integers in array must be positive");
} else if (flag == 1 && i > 0) {
throw new IllegalArgumentException("all integers in array must be negative");
}
r += i;
}
return r;
}
public static <T> T weightedRandom(Map<T, Float> weights) {
if (weights.size() == 0) return null;
int totalWeight = 0;
for (float weight : weights.values()) {
totalWeight += weight;
}
Random random = new Random();
float f = random.nextFloat() * totalWeight;
for (Map.Entry<T, Float> e : weights.entrySet()) {
f -= e.getValue();
if (f < 0) return e.getKey();
}
return null;
}
public static <T> List<T> listFrom(T element) {
List<T> list = new ArrayList<>();
list.add(element);
return list;
}
}

View file

@ -1,92 +0,0 @@
package com.zixiken.dimdoors.shared.util;
import com.zixiken.dimdoors.DimDoors;
import java.util.Random;
import net.minecraft.util.EnumFacing;
/**
* @author Robijnvogel
*/
public class RandomUtils {
/**
* Returns either true or false, based on a weighted random, taking in
* account the parameters as the weights for true and false as outcomes. For
* instance: (2, 3) should return true in 40% of the cases and false in 60%
* of the cases.
*
* @param trueWeight the chance weight that this method will return true
* @param falseWeight the chance weight that this method will return false
* @pre {@code trueWeight > 0 && falseWeight > 0}
* @throws IllegalArgumentException if precondition is violated
* @return true or false
*/
public static boolean weightedBoolean(int trueWeight, int falseWeight) { //@todo make this a utility function
if (trueWeight <= 0 || falseWeight <= 0) {
throw new IllegalArgumentException("Either of both weights were 0 or lower. Both should be at least 1.");
}
Random random = new Random();
return random.nextInt(trueWeight + falseWeight) < trueWeight;
}
/**
* This method returns the sum of {@code base} and a random element of
* {@code transformations} the weight of each of the entries in
*
* @param base the base value to transform from
* @param transformations the possible transformations
* @param weights the chance-weight of those transformations
* @pre {@code transformations.length = weights.length} && {@code (\forall i; intArray.has(i); i >= 0)}
* && {@code MathUtils.arraySum(weights, 1) > 0}
* @throws IllegalArgumentException if precondition is violated
* @return the sum of {@code base} and the value of an element in
* {@code transformations}
*/
public static int transformRandomly(int base, int[] transformations, int[] weights) {
if (transformations.length != weights.length) {
throw new IllegalArgumentException("pre was violated, transformations.length != weights.length");
}
Random random = new Random();
int weightSum = MathUtils.arraySum(weights, (short) 0);
if (weightSum <= 0) {
throw new IllegalArgumentException("pre was violated, MathUtils.arraySum(weights, 1) <= 0");
}
int choice = random.nextInt(weightSum);
for (int i = 0; i < weights.length; i++) {
choice -= weights[i];
if (choice < 0) {
return base + transformations[i];
}
}
throw new IllegalStateException("");
}
/**
* This method returns a Location that is determined by offsetting
* origLocation in the x and z direction by a randomly positive or negative
* random integer value, both based on the formula:
* {@code randomInt((base * depth) ^ power)}
*
* @param base this value is configured in the config files of DimDoors
* @param power this value is configured in the config files of DimDoors
* @param depth this should be the depth of the newly generated dungeon
* pocket
* @pre {@code base > 0 && depth > 0 && power >= 0 && origLocation != null}
* @throws IllegalArgumentException if pre is violated
* @param origLocation the original location to offset from
* @return a Location for which the x and z coordinates have both been
* offset by random values between {@code -(base * depth) ^ power)} and
* {@code ((base * depth) ^ power)} and y and dimensionID are the same as
* {@code origLocation}'s
*/
public static Location transformLocationRandomly(int base, double power, int depth, Location origLocation) {
if (base <= 0 || depth <= 0 || power < 0 || origLocation == null) {
throw new IllegalArgumentException("pre was violated");
}
Random random = new Random();
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

@ -17,7 +17,7 @@ import net.minecraftforge.common.DimensionManager;
public class DimDoorDimensions {
public static DimensionType LIMBO = null;
public static DimensionType limbo = null;
@Getter private static int minPocketDimID;
@Getter private static int maxPocketDimID;
private static final List<EnumPocketType> pocketTypes = new ArrayList<>();
@ -32,7 +32,7 @@ public class DimDoorDimensions {
// Lowercase names because all minecraft dimensions are lowercase, _pockets suffix to make it clear what the world is
minPocketDimID = DDConfig.getBaseDimID();
int dimID = minPocketDimID;
LIMBO = DimensionType.register("limbo", "_limbo", dimID, WorldProviderLimbo.class, false);
limbo = DimensionType.register("limbo", "_limbo", dimID, WorldProviderLimbo.class, false);
limboDimID = dimID++;
pocketTypes.add(EnumPocketType.PRIVATE);
pocketDimensionTypes.put(EnumPocketType.PRIVATE, DimensionType.register("private_pockets", "_private", dimID, WorldProviderPersonalPocket.class, false));
@ -45,7 +45,7 @@ public class DimDoorDimensions {
pocketDimensionTypes.put(EnumPocketType.DUNGEON, DimensionType.register("dungeon_pockets", "_dungeon", dimID, WorldProviderDungeonPocket.class, false));
dungeonDimID = dimID;
registerDimension(LIMBO);
registerDimension(limbo);
for (EnumPocketType pocketType : pocketDimensionTypes.keySet()) {
registerDimension(pocketDimensionTypes.get(pocketType));
}

View file

@ -5,7 +5,7 @@ import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
public abstract class BaseGateway {
public BaseGateway() { }
public BaseGateway() {}
/**
* Generates the gateway centered on the given coordinates
@ -22,7 +22,7 @@ public abstract class BaseGateway {
* @return <code>true</code> true if the specified biome is a valid for generating this gateway, otherwise <code>false</code>
*/
protected boolean isBiomeValid(Biome biome) {
Biome[] biomes = this.getBiomes();
Biome[] biomes = getBiomes();
if (biomes != null) {
for (Biome b : biomes) {
if (b.equals(biome)) {

View file

@ -1,8 +1,8 @@
package com.zixiken.dimdoors.shared.world.gateways;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.util.Schematic;
import com.zixiken.dimdoors.shared.util.SchematicConverter;
import ddutils.schem.Schematic;
import com.zixiken.dimdoors.shared.tools.SchematicConverter;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@ -35,7 +35,7 @@ public abstract class BaseSchematicGateway extends BaseGateway {
if (streamOpened) {
try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
schematic = SchematicConverter.loadOldDimDoorSchematicFromNBT(schematicNBT, name);
schematic = SchematicConverter.convertSchematic(schematicNBT, name);
schematicDataStream.close();
} catch (IOException ex) {
DimDoors.log.error("Schematic file for " + name + " could not be read as a valid schematic NBT file.", ex);

View file

@ -33,7 +33,7 @@ public class GatewayGenerator implements IWorldGenerator
private BaseGateway defaultGateway;
public GatewayGenerator() {
this.initialize();
initialize();
}
private void initialize() {
@ -51,7 +51,7 @@ public class GatewayGenerator implements IWorldGenerator
// Also don't generate anything in the Nether, The End, or in Witchery's Spirit World.
// We only match against Spirit World using hashing to speed up the process a little (hopefully).
int dimensionID = world.provider.getDimension();
if (world.isRemote || (world.provider instanceof WorldProviderPocket) || (dimensionID == END_DIMENSION_ID) || (dimensionID == NETHER_DIMENSION_ID)) {
if (world.isRemote || world.provider instanceof WorldProviderPocket || dimensionID == END_DIMENSION_ID || dimensionID == NETHER_DIMENSION_ID) {
return;
}
@ -99,7 +99,7 @@ public class GatewayGenerator implements IWorldGenerator
// Build the gateway if we found a valid location
if (valid) {
ArrayList<BaseGateway> validGateways = new ArrayList<BaseGateway>();
ArrayList<BaseGateway> validGateways = new ArrayList<>();
for (BaseGateway gateway : gateways) {
if (gateway.isLocationValid(world, x, y, z)) {
validGateways.add(gateway);
@ -119,11 +119,11 @@ public class GatewayGenerator implements IWorldGenerator
//Check if the point is within the acceptable altitude range, the block above that point is empty,
//and the block two levels down is opaque and has a reasonable material. Plus that we're not building
//on top of bedrock.
return (pos.getY() >= MIN_RIFT_Y && pos.getY() <= MAX_RIFT_Y &&
return pos.getY() >= MIN_RIFT_Y && pos.getY() <= MAX_RIFT_Y &&
world.isAirBlock(pos.up()) &&
world.getBlockState(pos).getBlock() != Blocks.BEDROCK && //<-- Stops Nether roof spawning. DO NOT REMOVE!
world.getBlockState(pos.down()) != Blocks.BEDROCK &&
checkFoundationMaterial(world, pos.down()));
checkFoundationMaterial(world, pos.down());
}
private static boolean checkFoundationMaterial(World world, BlockPos pos) {
@ -131,7 +131,7 @@ public class GatewayGenerator implements IWorldGenerator
//or on top of strange things like tall grass, water, slabs, or torches.
//We also want to avoid generating things on top of the Nether's bedrock!
Material material = world.getBlockState(pos).getMaterial();
return (material != Material.LEAVES && material != Material.WOOD && material != Material.GOURD
&& world.isBlockNormalCube(pos, false) && world.getBlockState(pos).getBlock() != Blocks.BEDROCK);
return material != Material.LEAVES && material != Material.WOOD && material != Material.GOURD
&& world.isBlockNormalCube(pos, false) && world.getBlockState(pos).getBlock() != Blocks.BEDROCK;
}
}

View file

@ -1,6 +1,6 @@
package com.zixiken.dimdoors.shared.world.gateways;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockStoneBrick;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -14,8 +14,6 @@ public class GatewayTwoPillars extends BaseSchematicGateway {
@Override
protected void generateRandomBits(World world, int x, int y, int z) {
IBlockState state = Blocks.STONEBRICK.getDefaultState();
//Replace some of the ground around the gateway with bricks
for (int xc = -GATEWAY_RADIUS; xc <= GATEWAY_RADIUS; xc++) {
for (int zc = -GATEWAY_RADIUS; zc <= GATEWAY_RADIUS; zc++) {
@ -27,10 +25,10 @@ public class GatewayTwoPillars extends BaseSchematicGateway {
//chances of placing a block decrease as we get farther from the gateway's center.
if (Math.abs(xc) + Math.abs(zc) < world.rand.nextInt(2) + 3) {
//Place Stone Bricks
world.setBlockState(new BlockPos(x + xc, y, z + zc), state);
world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONEBRICK.getDefaultState());
} else if (Math.abs(xc) + Math.abs(zc) < world.rand.nextInt(3) + 3) {
//Place Cracked Stone Bricks
world.setBlockState(new BlockPos(x + xc, y, z + zc), state); //TODO find out what the data for cracked Stonebrick is.
world.setBlockState(new BlockPos(x + xc, y, z + zc), Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.CRACKED));
}
}
}

View file

@ -93,7 +93,7 @@ public class LimboDecay {
int x, y, z;
int sectionY;
int limboHeight;
int[] limbo = DimensionManager.getDimensions(DimDoorDimensions.LIMBO);
int[] limbo = DimensionManager.getDimensions(DimDoorDimensions.limbo);
for (Integer i : limbo){

View file

@ -1,10 +1,10 @@
package com.zixiken.dimdoors.shared.world.limbodimension;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.CloudRenderBlank;
import ddutils.render.CloudRenderBlank;
import com.zixiken.dimdoors.shared.blocks.BlockFabric;
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import com.zixiken.dimdoors.shared.util.Location;
import ddutils.Location;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import com.zixiken.dimdoors.shared.world.ModBiomes;
import net.minecraft.entity.Entity;
@ -85,7 +85,7 @@ public class WorldProviderLimbo extends WorldProvider {
public static Location getLimboSkySpawn(EntityPlayer player) {
int x = (int) player.posX + MathHelper.clamp(player.world.rand.nextInt(), -100, 100); // TODO: -properties.LimboEntryRange, properties.LimboEntryRange);
int z = (int) player.posZ + MathHelper.clamp(player.world.rand.nextInt(), -100, 100); // TODO: -properties.LimboEntryRange, properties.LimboEntryRange);
return new Location(DimDoorDimensions.LIMBO.getId(), x, 700, z);
return new Location(DimDoorDimensions.limbo.getId(), x, 700, z);
}
@Override
@ -97,7 +97,7 @@ public class WorldProviderLimbo extends WorldProvider {
@Override
public DimensionType getDimensionType() {
return DimDoorDimensions.LIMBO;
return DimDoorDimensions.limbo;
}

View file

@ -1,6 +1,6 @@
package com.zixiken.dimdoors.shared.world.pocketdimension;
import com.zixiken.dimdoors.client.CloudRenderBlank;
import ddutils.render.CloudRenderBlank;
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import com.zixiken.dimdoors.shared.world.ModBiomes;
@ -26,7 +26,7 @@ public class WorldProviderDungeonPocket extends WorldProviderPocket {
@Override
public int getRespawnDimension(EntityPlayerMP player) {
return DimDoorDimensions.LIMBO.getId();
return DimDoorDimensions.limbo.getId();
}
@SideOnly(Side.CLIENT)

View file

@ -1,7 +1,7 @@
package com.zixiken.dimdoors.shared.world.pocketdimension;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.CloudRenderBlank;
import ddutils.render.CloudRenderBlank;
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.entity.Entity;

View file

@ -1,6 +1,6 @@
package com.zixiken.dimdoors.shared.world.pocketdimension;
import com.zixiken.dimdoors.client.CloudRenderBlank;
import ddutils.render.CloudRenderBlank;
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
import com.zixiken.dimdoors.shared.world.ModBiomes;
import net.minecraft.entity.Entity;

View file

@ -1,10 +1,9 @@
package com.zixiken.dimdoors.shared.util;
package ddutils;
import com.zixiken.dimdoors.DimDoors;
import java.io.Serializable;
import lombok.Getter;
import lombok.ToString;
import lombok.Value;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
@ -12,16 +11,16 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
/**
*
* @author Robijnvogel
*/
@ToString
@ToString @Value
public class Location implements Serializable {
@Getter private int dimID; // TODO: remove getter and make final?
@Getter private BlockPos pos;
int dim;
private BlockPos pos;
public Location(World world, BlockPos pos) {
this(world.provider.getDimension(), pos);
@ -31,15 +30,19 @@ public class Location implements Serializable {
this(world, new BlockPos(x, y, z));
}
public Location(int dimID, int x, int y, int z) {
this(dimID, new BlockPos(x, y, z));
public Location(int dim, int x, int y, int z) {
this(dim, new BlockPos(x, y, z));
}
public Location(int dimID, BlockPos pos) {
this.dimID = dimID;
this.pos = pos; //copyOf
public Location(int dim, BlockPos pos) {
this.dim = dim;
this.pos = pos;
}
public int getX() { return pos.getX(); }
public int getY() { return pos.getY(); }
public int getZ() { return pos.getZ(); }
public TileEntity getTileEntity() {
return getWorld().getTileEntity(pos);
}
@ -49,7 +52,7 @@ public class Location implements Serializable {
}
public WorldServer getWorld() {
return DimDoors.proxy.getWorldServer(dimID);
return DimensionManager.getWorld(dim);
}
public static Location getLocation(TileEntity tileEntity) {
@ -66,7 +69,7 @@ public class Location implements Serializable {
public static NBTTagCompound writeToNBT(Location location) {
NBTTagCompound locationNBT = new NBTTagCompound();
locationNBT.setInteger("worldID", location.dimID);
locationNBT.setInteger("worldID", location.dim);
locationNBT.setInteger("x", location.pos.getX());
locationNBT.setInteger("y", location.pos.getY());
locationNBT.setInteger("z", location.pos.getZ());
@ -88,16 +91,11 @@ public class Location implements Serializable {
return false;
}
Location other = (Location) obj;
return other.dimID == dimID && other.pos.equals(pos);
return other.dim == dim && other.pos.equals(pos);
}
@Override
public int hashCode() {
return pos.hashCode() * 31 + dimID; // TODO
}
public void loadfrom(Location location) {
dimID = location.dimID;
pos = location.pos;
return pos.hashCode() * 31 + dim; // TODO
}
}

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.util;
package ddutils;
import net.minecraft.entity.Entity;

View file

@ -1,10 +1,9 @@
package com.zixiken.dimdoors.shared.util;
package ddutils;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Robijnvogel
*/
public class StringUtils {

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.util;
package ddutils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@ -24,7 +24,7 @@ public class TeleportUtils {
}
public static Entity teleport(Entity entity, Location location, float yaw, float pitch) {
return teleport(entity, location.getDimID(), location.getPos().getX() + .5, location.getPos().getY(), location.getPos().getZ() + .5, yaw, pitch);
return teleport(entity, location.getDim(), location.getPos().getX() + .5, location.getPos().getY(), location.getPos().getZ() + .5, yaw, pitch);
}
public static Entity teleport(Entity entity, BlockPos pos, float yaw, float pitch) {

View file

@ -1,11 +1,11 @@
package com.zixiken.dimdoors.shared.util;
package ddutils;
import com.zixiken.dimdoors.DimDoors;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
public class WorldUtils {
public static World getWorld(int dim) {
return DimDoors.proxy.getWorldServer(dim);
return DimensionManager.getWorld(dim);
}
public static int getDim(World world) {

View file

@ -1,7 +1,6 @@
package com.zixiken.dimdoors.shared.blocks;
package ddutils.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.pockets;
package ddutils.math;
import lombok.Value;

View file

@ -0,0 +1,30 @@
package ddutils.math;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class MathUtils {
public static <T> T weightedRandom(Map<T, Float> weights) {
if (weights.size() == 0) return null;
int totalWeight = 0;
for (float weight : weights.values()) {
totalWeight += weight;
}
Random random = new Random();
float f = random.nextFloat() * totalWeight;
for (Map.Entry<T, Float> e : weights.entrySet()) {
f -= e.getValue();
if (f < 0) return e.getKey();
}
return null;
}
public static <T> List<T> listFrom(T element) {
List<T> list = new ArrayList<>();
list.add(element);
return list;
}
}

View file

@ -0,0 +1,106 @@
package ddutils.math;
import java.util.Random;
/**
* @author Robijnvogel
*/
public class RandomUtils { // These utils aren't being used by DimDoors!
/**
* Compares the integers in two arrays and returns true if any integer in
* the first set is within range 0 to {@code difference} - 1 of any integer
* in the second array.
*
* @param set1 the first integer array to compare
* @param difference see method description
* @param set2 the second integer array to compare
* @return {@code (\exists i, j; ; abs(set1[i] - set2[j]) < difference }
* @throws IllegalArgumentException if precondition is violated
* @pre difference >= 0
*/
public static boolean withinDistanceOf(int[] set1, int difference, int[] set2) throws IllegalArgumentException {
if (difference < 0) throw new IllegalArgumentException("Difference must be larger than 0");
for (int e1 : set1) {
for (int e2 : set2) {
if (Math.max(e1, e2) - Math.min(e1, e2) < difference) return true;
}
}
return false;
}
/**
* Returns the sum of the values of all integer elements in an integer array
*
* @param intArray the integers to calculate the sum of
* @param flag this flag is meant to check if all elements in the array must
* be positive (0), negative(1), or it doesn't matter (anything else)
* @return {@code sum(i = 0; intArray.has(i); intArray[i]) }
* @throws IllegalArgumentException if precondition is violated
* @pre {@code (flag != 0 && flag != 1) || (flag == 0 && (\forall i; intArray.has(i); i >= 0)) || (flag == 1 && (\forall i; intArray.has(i); i <= 0))}
*/
public static int arraySum(int[] intArray, short flag) {
int r = 0;
for (int i : intArray) { //check flag
if (flag == 0 && i < 0) {
throw new IllegalArgumentException("all integers in array must be positive");
} else if (flag == 1 && i > 0) {
throw new IllegalArgumentException("all integers in array must be negative");
}
r += i;
}
return r;
}
/**
* Returns either true or false, based on a weighted random, taking in
* account the parameters as the weights for true and false as outcomes. For
* instance: (2, 3) should return true in 40% of the cases and false in 60%
* of the cases.
*
* @param trueWeight the chance weight that this method will return true
* @param falseWeight the chance weight that this method will return false
* @return true or false
* @throws IllegalArgumentException if precondition is violated
* @pre {@code trueWeight > 0 && falseWeight > 0}
*/
public static boolean weightedBoolean(int trueWeight, int falseWeight) {
if (trueWeight <= 0 || falseWeight <= 0) {
throw new IllegalArgumentException("Either of both weights were 0 or lower. Both should be at least 1.");
}
Random random = new Random();
return random.nextInt(trueWeight + falseWeight) < trueWeight;
}
/**
* This method returns the sum of {@code base} and a random element of
* {@code transformations} the weight of each of the entries in
*
* @param base the base value to transform from
* @param transformations the possible transformations
* @param weights the chance-weight of those transformations
* @return the sum of {@code base} and the value of an element in
* {@code transformations}
* @throws IllegalArgumentException if precondition is violated
* @pre {@code transformations.length = weights.length} && {@code (\forall i; intArray.has(i); i >= 0)}
* && {@code MathUtils.arraySum(weights, 1) > 0}
*/
public static int transformRandomly(int base, int[] transformations, int[] weights) {
if (transformations.length != weights.length) {
throw new IllegalArgumentException("pre was violated, transformations.length != weights.length");
}
Random random = new Random();
int weightSum = arraySum(weights, (short) 0);
if (weightSum <= 0) {
throw new IllegalArgumentException("pre was violated, RandomUtils.arraySum(weights, 1) <= 0");
}
int choice = random.nextInt(weightSum);
for (int i = 0; i < weights.length; i++) {
choice -= weights[i];
if (choice < 0) {
return base + transformations[i];
}
}
throw new IllegalStateException("");
}
}

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.util;
package ddutils.nbt;
import net.minecraft.nbt.NBTTagCompound;

View file

@ -1,10 +1,11 @@
package com.zixiken.dimdoors.shared.util;
package ddutils.nbt;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.Vec3i;
import java.util.HashMap;
import java.util.Map;
public class NBTUtils {
public static Map<String, Integer> readMapStringInteger(NBTTagCompound nbt) {
HashMap<String, Integer> map = new HashMap<>();

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.client;
package ddutils.render;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.util;
package ddutils.render;
import lombok.Value;

View file

@ -1,4 +1,4 @@
package com.zixiken.dimdoors.shared.util;
package ddutils.schem;
import java.util.ArrayList;
import java.util.HashMap;
@ -6,7 +6,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
@ -21,24 +20,23 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
/**
*
* @author Robijnvogel
*/
public class Schematic {
@Getter int version = 1;
@Getter String author = null;
@Getter String schematicName = "Unknown";
@Getter long creationDate;
@Getter String[] requiredMods = {};
@Getter short width;
@Getter short height;
@Getter short length;
@Getter int[] offset = {0, 0, 0};
@Getter int paletteMax;
@Getter List<IBlockState> pallette = new ArrayList<>();
@Getter int[][][] blockData; //[x][y][z]
@Getter List<NBTTagCompound> tileEntities = new ArrayList<>();
public int version = 1;
public String author = null;
public String schematicName = "Unknown";
public long creationDate;
public String[] requiredMods = {};
public short width;
public short height;
public short length;
public int[] offset = {0, 0, 0};
public int paletteMax;
public List<IBlockState> pallette = new ArrayList<>();
public int[][][] blockData; //[x][y][z]
public List<NBTTagCompound> tileEntities = new ArrayList<>();
public static Schematic loadFromNBT(NBTTagCompound nbt, String name) {
Schematic schematic = new Schematic();
@ -65,7 +63,6 @@ public class Schematic {
}
}
//@todo, check if the required mods are loaded, otherwise abort
schematic.width = nbt.getShort("Width"); //Width is required
schematic.height = nbt.getShort("Height"); //Height is required
schematic.length = nbt.getShort("Length"); //Length is required
@ -232,8 +229,8 @@ public class Schematic {
public static void place(Schematic schematic, World world, int xBase, int yBase, int zBase) {
// Place the schematic's blocks
List<IBlockState> palette = schematic.getPallette();
int[][][] blockData = schematic.getBlockData();
List<IBlockState> palette = schematic.pallette;
int[][][] blockData = schematic.blockData;
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++) {
@ -243,15 +240,17 @@ public class Schematic {
}
// Set TileEntity data
for (NBTTagCompound tileEntityNBT : schematic.getTileEntities()) {
for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
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.readFromNBT(tileEntityNBT);
// Correct the position
tileEntity.setWorld(world);
tileEntity.setPos(pos); //correct the position
tileEntity.markDirty();
}