Merge pull request #84 from SenseiKiwi/rewrite

Rewrite Continued
This commit is contained in:
StevenRS11 2013-09-05 19:57:33 -07:00
commit 23efc90765
19 changed files with 305 additions and 209 deletions

View file

@ -1,17 +0,0 @@
package StevenDimDoors.mod_pocketDim;
public class DimUpdatePacket
{
public DimUpdatePacket(int dim)
{
}
}

View file

@ -12,8 +12,8 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
import StevenDimDoors.mod_pocketDim.util.Point4D;

View file

@ -18,8 +18,8 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData;

View file

@ -10,8 +10,8 @@ import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import cpw.mods.fml.relauncher.Side;

View file

@ -1,5 +1,6 @@
package StevenDimDoors.mod_pocketDim;
package StevenDimDoors.mod_pocketDim.core;
import java.util.ArrayList;
import java.util.Random;
import net.minecraft.entity.Entity;
@ -16,9 +17,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
import cpw.mods.fml.common.registry.GameRegistry;
@ -26,6 +25,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
public class DDTeleporter
{
private static final Random random = new Random();
private static int END_DIMENSION_ID = 1;
public static int cooldown = 0;
private DDTeleporter() { }
@ -193,12 +193,7 @@ public class DDTeleporter
if (difDest)
{
// Destination isn't loaded? Then we need to load it.
newWorld = DimensionManager.getWorld(destination.getDimension());
if (newWorld == null)
{
DimensionManager.initDimension(destination.getDimension());
newWorld = DimensionManager.getWorld(destination.getDimension());
}
newWorld = PocketManager.loadDimension(destination.getDimension());
}
else
{
@ -231,10 +226,10 @@ public class DDTeleporter
oldWorld.getPlayerManager().removePlayer(player);
newWorld.getPlayerManager().addPlayer(player);
player.theItemInWorldManager.setWorld((WorldServer)newWorld);
player.theItemInWorldManager.setWorld(newWorld);
// Synchronize with the server so the client knows what time it is and what it's holding.
player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer)newWorld);
player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, newWorld);
player.mcServer.getConfigurationManager().syncPlayerInventory(player);
for(Object potionEffect : player.getActivePotionEffects())
{
@ -346,31 +341,150 @@ public class DDTeleporter
return;
}
if (link.linkType() == LinkTypes.RANDOM)
{
Point4D randomDestination = getRandomDestination();
if (randomDestination != null)
{
entity = teleportEntity(entity, randomDestination);
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
}
}
else
{
entity = teleportEntity(entity, link.destination());
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
}
}
private static boolean initializeDestination(DimLink link, DDProperties properties)
{
// FIXME: Change this later to support rooms that have been wiped and must be regenerated.
// FIXME: Add code for restoring the destination-side door.
// We might need to implement regeneration for REVERSE links as well.
if (link.hasDestination())
{
return true;
}
// Check the destination type and respond accordingly
//FIXME: Add missing link types.
//FIXME: Add code for restoring the destination-side door.
switch (link.linkType())
{
case LinkTypes.DUNGEON:
return PocketBuilder.generateNewDungeonPocket(link, properties);
case LinkTypes.POCKET:
return PocketBuilder.generateNewPocket(link, properties);
case LinkTypes.SAFE_EXIT:
return generateSafeExit(link, properties);
case LinkTypes.DUNGEON_EXIT:
return generateDungeonExit(link, properties);
case LinkTypes.UNSAFE_EXIT:
return generateUnsafeExit(link);
case LinkTypes.NORMAL:
case LinkTypes.REVERSE:
case LinkTypes.RANDOM:
return true;
default:
throw new IllegalArgumentException("link has an unrecognized link type.");
}
}
private static Point4D getRandomDestination()
{
// Our aim is to return a random link's source point
// so that a link of type RANDOM can teleport a player there.
// Restrictions:
// 1. Ignore links with their source inside a pocket dimension.
// 2. Ignore links with link type RANDOM.
// Iterate over the root dimensions. Pocket dimensions cannot be roots.
// Don't just pick a random root and a random link within that root
// because we want to have unbiased selection among all links.
ArrayList<Point4D> matches = new ArrayList<Point4D>();
for (NewDimData dimension : PocketManager.getRootDimensions())
{
for (DimLink link : dimension.getAllLinks())
{
if (link.linkType() != LinkTypes.RANDOM)
{
matches.add(link.source());
}
}
}
// Pick a random point, if any is available
if (!matches.isEmpty())
{
return matches.get( random.nextInt(matches.size()) );
}
else
{
return null;
}
}
private static boolean generateUnsafeExit(DimLink link)
{
// An unsafe exit teleports the user to exactly the same coordinates
// as the link source, except located at the dimension's root dimension.
// This is very risky, as we make no effort to clear an air pocket or
// place a platform at the destination. We also don't place a reverse
// link at the destination, so it's a one-way trip. Good luck!
// To avoid loops, don't generate a destination if the player is
// already in a non-pocket dimension.
NewDimData current = PocketManager.getDimensionData(link.source.getDimension());
if (current.isPocketDimension())
{
Point4D source = link.source();
current.root().setDestination(link, source.getX(), source.getY(), source.getZ());
return true;
}
else
{
return false;
}
}
private static boolean generateSafeExit(DimLink link, DDProperties properties)
{
NewDimData current = PocketManager.getDimensionData(link.source.getDimension());
return generateSafeExit(current.root(), link, properties);
}
private static boolean generateDungeonExit(DimLink link, DDProperties properties)
{
// A dungeon exit acts the same as a safe exit, but has the chance of
// taking the user to any non-pocket dimension, excluding Limbo and The End.
ArrayList<NewDimData> roots = PocketManager.getRootDimensions();
for (int attempts = 0; attempts < 10; attempts++)
{
NewDimData selection = roots.get( random.nextInt(roots.size()) );
if (selection.id() != END_DIMENSION_ID && selection.id() != properties.LimboDimensionID)
{
return generateSafeExit(selection, link, properties);
}
}
return false;
}
private static boolean generateSafeExit(NewDimData target, DimLink link, DDProperties properties)
{
// A safe exit attempts to place a Warp Door in a dimension with
// some precautions to protect the player. The X and Z coordinates
// are fixed to match the source, but the Y coordinate is chosen by
// searching for a safe location to place the door. The direction of
// the vertical search is away from the map boundary closest to
// the source Y. In other words, if a player is really high up, the
// search proceeds down. If a player is near the bottom of the map,
// the search proceeds up. If a safe destination cannot be found,
// then we return false and the source-side door slams shut.
// FIXME: Add code here!
return false;
}
}

View file

@ -5,17 +5,17 @@ public class LinkTypes
private LinkTypes() { }
public static final int ENUM_MIN = 0;
public static final int ENUM_MAX = 8;
public static final int ENUM_MAX = 7;
public static final int CLIENT_SIDE = -1337;
// WARNING: Don't modify these values carelessly or you'll risk breaking links in existing worlds!
public static final int NORMAL = 0;
public static final int LIMBO = 1;
public static final int POCKET = 2;
public static final int DUNGEON = 3;
public static final int RANDOM = 4;
public static final int DUNGEON_EXIT = 5;
public static final int SAFE_EXIT = 6;
public static final int UNSAFE_EXIT = 7;
public static final int RANDOM_DUNGEON = 8;
public static final int POCKET = 1;
public static final int DUNGEON = 2;
public static final int RANDOM = 3;
public static final int DUNGEON_EXIT = 4;
public static final int SAFE_EXIT = 5;
public static final int UNSAFE_EXIT = 6;
public static final int REVERSE = 7;
}

View file

@ -4,17 +4,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.Compactor;
import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource;
@ -100,6 +98,7 @@ public class PocketManager
private static volatile boolean isSaving = false;
private static final UpdateWatcherProxy<Point4D> linkWatcher = new UpdateWatcherProxy<Point4D>();
private static final UpdateWatcherProxy<ClientDimData> dimWatcher = new UpdateWatcherProxy<ClientDimData>();
private static ArrayList<NewDimData> rootDimensions = null;
//HashMap that maps all the dimension IDs registered with DimDoors to their DD data.
private static HashMap<Integer, InnerDimData> dimensionData = null;
@ -126,6 +125,7 @@ public class PocketManager
isLoading = true;
dimensionData = new HashMap<Integer, InnerDimData>();
rootDimensions = new ArrayList<NewDimData>();
//Register Limbo
DDProperties properties = DDProperties.instance();
@ -286,27 +286,20 @@ public class PocketManager
}
}
public static boolean removeRift(World world, int x, int y, int z, int range, EntityPlayer player, ItemStack item)
public static WorldServer loadDimension(int id)
{
//Function called by rift tile entities and the rift remover to find and spread between rifts.
//Does not actually unregister the rift data, see deleteRift for that.
NewDimData dimension = getDimensionData(world);
DimLink nearest = dimension.findNearestRift(world, range, x, y, z);
if (nearest != null)
WorldServer world = DimensionManager.getWorld(id);
if (world == null)
{
Point4D location = nearest.source();
TileEntity tileEntity = world.getBlockTileEntity(location.getX(), location.getY(), location.getZ());
if (tileEntity != null)
{
TileEntityRift riftEntity = (TileEntityRift) tileEntity;
riftEntity.shouldClose = true;
item.damageItem(1, player);
return true;
DimensionManager.initDimension(id);
world = DimensionManager.getWorld(id);
}
else if (world.provider == null)
{
DimensionManager.initDimension(id);
world = DimensionManager.getWorld(id);
}
return false;
return world;
}
public static NewDimData registerDimension(World world)
@ -336,6 +329,12 @@ public class PocketManager
InnerDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon, linkWatcher);
dimensionData.put(dimensionID, dimension);
if (!dimension.isPocketDimension())
{
rootDimensions.add(dimension);
}
dimWatcher.onCreated(new ClientDimData(dimension));
return dimension;
}
@ -344,6 +343,9 @@ public class PocketManager
// No need to raise events here since this code should only run on the client side
// getDimensionData() always handles root dimensions properly, even if the weren't defined before
// SenseiKiwi: I'm a little worried about how getDimensionData will raise
// an event when it creates any root dimensions... Needs checking later.
InnerDimData root = (InnerDimData) getDimensionData(rootID);
InnerDimData dimension;
@ -389,6 +391,12 @@ public class PocketManager
return dimensionData.values();
}
@SuppressWarnings("unchecked")
public static ArrayList<NewDimData> getRootDimensions()
{
return (ArrayList<NewDimData>) rootDimensions.clone();
}
public static void unload()
{
if (!isLoaded)
@ -399,6 +407,7 @@ public class PocketManager
save();
unregisterPockets();
dimensionData = null;
rootDimensions = null;
isLoaded = false;
}

View file

@ -285,7 +285,7 @@ public class DungeonSchematic extends Schematic {
private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, DimLink entryLink)
{
DimLink reverseLink = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), LinkTypes.NORMAL);
DimLink reverseLink = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), LinkTypes.REVERSE);
Point4D destination = entryLink.source();
NewDimData prevDim = PocketManager.getDimensionData(destination.getDimension());
prevDim.setDestination(reverseLink, destination.getX(), destination.getY(), destination.getZ());

View file

@ -6,12 +6,10 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
@ -41,12 +39,12 @@ public abstract class BaseItemDoor extends ItemDoor
public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);
@Override
public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10);
public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ);
public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, boolean requireLink, boolean reduceStack)
public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, boolean requireLink, boolean reduceStack)
{
//FIXME: Without any sort of this documentation, this condition is like magic -_- ~SenseiKiwi
if (par7 == 1 && !world.isRemote)
// Only place doors on top of blocks - check if we're targeting the top side
if (side == 1 && !world.isRemote)
{
int blockID = world.getBlockId(x, y, z);
if (blockID != 0)
@ -58,7 +56,7 @@ public abstract class BaseItemDoor extends ItemDoor
}
if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) &&
player.canPlayerEdit(x, y, z, par7, stack) && player.canPlayerEdit(x, y + 1, z, par7, stack) &&
player.canPlayerEdit(x, y, z, side, stack) && player.canPlayerEdit(x, y + 1, z, side, stack) &&
(!requireLink || PocketManager.getLink(x, y + 1, z, world) != null))
{
int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
@ -74,31 +72,6 @@ public abstract class BaseItemDoor extends ItemDoor
return false;
}
@Override
public final MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
{
float var4 = 1.0F;
float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4;
double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset;
double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4;
Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11);
float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI);
float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI);
float var16 = -MathHelper.cos(-var5 * 0.017453292F);
float var17 = MathHelper.sin(-var5 * 0.017453292F);
float var18 = var15 * var16;
float var20 = var14 * var16;
double var21 = 5.0D;
if (par2EntityPlayer instanceof EntityPlayerMP)
{
var21 = 4;
}
Vec3 var23 = var13.addVector((double) var18 * var21, (double)var17 * var21, (double)var20 * var21);
return par1World.rayTraceBlocks_do_do(var13, var23, true, false);
}
@Override
public abstract ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player);
@ -109,7 +82,7 @@ public abstract class BaseItemDoor extends ItemDoor
return false;
}
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, false);
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, true);
if (hit != null)
{
if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID)
@ -120,9 +93,8 @@ public abstract class BaseItemDoor extends ItemDoor
int x = hit.blockX;
int y = hit.blockY;
int z = hit.blockZ;
int par7 = 0;
if (player.canPlayerEdit(x, y, z, par7, item) && player.canPlayerEdit(x, y - 1, z, par7, item))
if (player.canPlayerEdit(x, y, z, hit.sideHit, item) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, item))
{
if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z))
{

View file

@ -28,9 +28,9 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemRiftBlade extends ItemSword
{
private static DDProperties properties = null;
private final DDProperties properties;
public ItemRiftBlade(int itemID, EnumToolMaterial material)
public ItemRiftBlade(int itemID, EnumToolMaterial material, DDProperties properties)
{
super(itemID, material);
@ -38,10 +38,10 @@ public class ItemRiftBlade extends ItemSword
this.setMaxStackSize(1);
this.setMaxDamage(500);
this.hasSubtypes = false;
if (properties == null)
properties = DDProperties.instance();
this.properties = properties;
}
@Override
@SideOnly(Side.CLIENT)
public boolean isFull3D()
{
@ -224,20 +224,19 @@ public class ItemRiftBlade extends ItemSword
{
if (PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world) != null)
{
Block var11 = mod_pocketDim.transientDoor;
int par4 = hit.blockX;
int par5 = hit.blockY;
int par6 = hit.blockZ;
int par7 = 0;
Block block = mod_pocketDim.transientDoor;
int x = hit.blockX;
int y = hit.blockY;
int z = hit.blockZ;
if (player.canPlayerEdit(par4, par5, par6, par7, stack) && player.canPlayerEdit(par4, par5 + 1, par6, par7, stack)&&!world.isRemote)
if (player.canPlayerEdit(x, y, z, hit.sideHit, stack) && player.canPlayerEdit(x, y + 1, z, hit.sideHit, stack) && !world.isRemote)
{
int var12 = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
int orientation = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
if (BaseItemDoor.canPlace(world, par4, par5, par6) &&
BaseItemDoor.canPlace(world, par4, par5 - 1, par6))
if (BaseItemDoor.canPlace(world, x, y, z) &&
BaseItemDoor.canPlace(world, x, y - 1, z))
{
ItemDimensionalDoor.placeDoorBlock(world, par4, par5 - 1, par6, var12, var11);
ItemDimensionalDoor.placeDoorBlock(world, x, y - 1, z, orientation, block);
player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1);
stack.damageItem(10, player);
}
@ -273,9 +272,9 @@ public class ItemRiftBlade extends ItemSword
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y,
int z, int par7, float par8, float par9, float par10)
int z, int side, float hitX, float hitY, float hitZ)
{
if (BaseItemDoor.tryItemUse(mod_pocketDim.transientDoor, stack, player, world, x, y, z, par7, true, false))
if (BaseItemDoor.tryItemUse(mod_pocketDim.transientDoor, stack, player, world, x, y, z, side, true, false))
{
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1);
return true;

View file

@ -60,7 +60,7 @@ public class ItemRiftSignature extends Item
//We don't check for replaceable blocks. The user can deal with that. <_<
y += 2; //Increase y by 2 to place the rift at head level
if (!player.canPlayerEdit(x, y, z, 0, stack))
if (!player.canPlayerEdit(x, y, z, side, stack))
{
return true;
}

View file

@ -40,7 +40,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
// We don't check for replaceable blocks. The user can deal with that. <_<
y += 2; //Increase y by 2 to place the rift at head level
if (!player.canPlayerEdit(x, y, z, 0, stack))
if (!player.canPlayerEdit(x, y, z, side, stack))
{
return true;
}

View file

@ -5,27 +5,28 @@ import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class itemRiftRemover extends Item
{
public itemRiftRemover(int par1, Material par2Material)
public itemRiftRemover(int itemID, Material par2Material)
{
super(par1);
super(itemID);
this.setMaxStackSize(1);
this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
this.setMaxDamage(5);
this.hasSubtypes = true;
this.setMaxDamage(4);
}
public void registerIcons(IconRegister par1IconRegister)
@ -33,41 +34,82 @@ public class itemRiftRemover extends Item
this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName());
}
public static MovingObjectPosition getBlockTarget(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
float var4 = 1.0F;
float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4;
double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset;
double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4;
Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11);
float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI);
float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI);
float var16 = -MathHelper.cos(-var5 * 0.017453292F);
float var17 = MathHelper.sin(-var5 * 0.017453292F);
float var18 = var15 * var16;
float var20 = var14 * var16;
double var21 = 5.0D;
if (par2EntityPlayer instanceof EntityPlayerMP)
// We invoke PlayerControllerMP.onPlayerRightClick() from here so that Minecraft
// will invoke onItemUseFirst() on the client side. We'll tell it to pass the
// request to the server, which will make sure that rift-related changes are
// reflected on the server.
if (!world.isRemote)
{
var21 = 6;
}
Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21);
return par1World.rayTraceBlocks_do_do(var13, var23, true, false);
return stack;
}
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
MovingObjectPosition hit = getBlockTarget(par3EntityPlayer.worldObj, par3EntityPlayer, false);
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(world, player, true);
if (hit != null)
{
if (PocketManager.removeRift(par2World, hit.blockX, hit.blockY, hit.blockZ, 1, par3EntityPlayer, par1ItemStack))
int hx = hit.blockX;
int hy = hit.blockY;
int hz = hit.blockZ;
NewDimData dimension = PocketManager.getDimensionData(world);
DimLink link = dimension.getLink(hx, hy, hz);
if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null &&
player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack))
{
par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftClose", 0.8f, 1);
// Invoke onPlayerRightClick()
FMLClientHandler.instance().getClient().playerController.onPlayerRightClick(
player, world, stack, hx, hy, hz, hit.sideHit, hit.hitVec);
}
}
return par1ItemStack;
return stack;
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
// We want to use onItemUseFirst() here so that this code will run on the server side,
// so we don't need the client to send link-related updates to the server. Still,
// check whether we have a rift in sight before passing the request over.
// On integrated servers, the link won't be removed immediately because of the rift
// removal animation. That means we'll have a chance to check for the link before
// it's deleted. Otherwise the Rift Remover's durability wouldn't drop.
NewDimData dimension = PocketManager.getDimensionData(world);
DimLink link = dimension.getLink(x, y, z);
if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID && link != null &&
player.canPlayerEdit(x, y, z, side, stack))
{
// Tell the rift's tile entity to do its removal animation
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null && tileEntity instanceof TileEntityRift)
{
((TileEntityRift) tileEntity).shouldClose = true;
}
else if (!world.isRemote)
{
// Only set the block to air on the server side so that we don't
// tell the server to remove the rift block before it can use the
// Rift Remover. Otherwise, it won't know to reduce durability.
world.setBlockToAir(x, y, z);
}
if (world.isRemote)
{
// Tell the server about this
return false;
}
else
{
if (!player.capabilities.isCreativeMode)
{
stack.damageItem(1, player);
}
player.worldObj.playSoundAtEntity(player, "mods.DimDoors.sfx.riftClose", 0.8f, 1);
}
}
return true;
}
/**

View file

@ -185,7 +185,7 @@ public class mod_pocketDim
itemRiftRemover = (new itemRiftRemover(properties.RiftRemoverItemID, Material.wood)).setUnlocalizedName("itemRiftRemover");
itemStableFabric = (new ItemStableFabric(properties.StableFabricItemID, 0)).setUnlocalizedName("itemStableFabric");
itemChaosDoor = (new ItemUnstableDoor(properties.UnstableDoorItemID, Material.iron)).setUnlocalizedName("itemChaosDoor");
itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, EnumToolMaterial.GOLD)).setUnlocalizedName("ItemRiftBlade");
itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, EnumToolMaterial.GOLD, properties)).setUnlocalizedName("ItemRiftBlade");
itemStabilizedLinkSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig");
mod_pocketDim.limboBiome= (new BiomeGenLimbo(properties.LimboBiomeID));

View file

@ -3,7 +3,7 @@ package StevenDimDoors.mod_pocketDim.ticking;
import java.util.ArrayList;
import java.util.EnumSet;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

View file

@ -13,7 +13,7 @@ import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.world.LimboProvider;
import StevenDimDoors.mod_pocketDim.world.PocketProvider;

View file

@ -1,9 +1,6 @@
package StevenDimDoors.mod_pocketDim.world;
import StevenDimDoors.mod_pocketDim.ticking.MobMonolith;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.SpawnListEntry;
public class BiomeGenLimbo extends BiomeGenBase
{

View file

@ -1,8 +1,6 @@
package StevenDimDoors.mod_pocketDim.world;
import StevenDimDoors.mod_pocketDim.ticking.MobMonolith;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.SpawnListEntry;
public class BiomeGenPocket extends BiomeGenBase
{

View file

@ -61,17 +61,8 @@ public class PocketBuilder
NewDimData dimension = PocketManager.registerPocket(parent, true);
//Load a world
World world = DimensionManager.getWorld(dimension.id());
World world = PocketManager.loadDimension(dimension.id());
if (world == null)
{
DimensionManager.initDimension(dimension.id());
world = DimensionManager.getWorld(dimension.id());
}
if (world != null && world.provider == null)
{
DimensionManager.initDimension(dimension.id());
}
if (world == null || world.provider == null)
{
System.err.println("Could not initialize dimension for a dungeon!");
@ -282,17 +273,8 @@ public class PocketBuilder
NewDimData dimension = PocketManager.registerPocket(parent, false);
//Load a world
World world = DimensionManager.getWorld(dimension.id());
World world = PocketManager.loadDimension(dimension.id());
if (world == null)
{
DimensionManager.initDimension(dimension.id());
world = DimensionManager.getWorld(dimension.id());
}
if (world != null && world.provider == null)
{
DimensionManager.initDimension(dimension.id());
}
if (world == null || world.provider == null)
{
System.err.println("Could not initialize dimension for a pocket!");
@ -305,7 +287,7 @@ public class PocketBuilder
int orientation = getDoorOrientation(source, properties);
//Place a link leading back out of the pocket
DimLink reverseLink = dimension.createLink(source.getX(), destinationY, source.getZ(), LinkTypes.NORMAL);
DimLink reverseLink = dimension.createLink(source.getX(), destinationY, source.getZ(), LinkTypes.REVERSE);
parent.setDestination(reverseLink, source.getX(), source.getY(), source.getZ());
//Build the actual pocket area