Changes
Made saving a bit more robust, now we only delete ones that where not modified. Also overhauled door placement, its all handled by the eventHandler now.
This commit is contained in:
parent
12e0fee70a
commit
42f0656b1b
7 changed files with 362 additions and 294 deletions
|
@ -19,6 +19,7 @@ import net.minecraftforge.event.entity.living.LivingFallEvent;
|
|||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.terraingen.InitMapGenEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
|
@ -32,218 +33,202 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
|
||||
public class EventHookContainer
|
||||
{
|
||||
private final DDProperties properties;
|
||||
|
||||
private final DDProperties properties;
|
||||
|
||||
public EventHookContainer(DDProperties properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.LOW)
|
||||
public void onInitMapGen(InitMapGenEvent event)
|
||||
{
|
||||
// Replace the Nether fortress generator with our own only if any gateways would ever generate.
|
||||
// This allows admins to disable our fortress overriding without disabling all gateways.
|
||||
// Replace the Nether fortress generator with our own only if any
|
||||
// gateways would ever generate.
|
||||
// This allows admins to disable our fortress overriding without
|
||||
// disabling all gateways.
|
||||
/*
|
||||
if (properties.FortressGatewayGenerationChance > 0 && properties.WorldRiftGenerationEnabled &&
|
||||
event.type == InitMapGenEvent.EventType.NETHER_BRIDGE)
|
||||
* if (properties.FortressGatewayGenerationChance > 0 &&
|
||||
* properties.WorldRiftGenerationEnabled && event.type ==
|
||||
* InitMapGenEvent.EventType.NETHER_BRIDGE) { event.newGen = new
|
||||
* DDNetherFortressGenerator(); }
|
||||
*/
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@ForgeSubscribe
|
||||
public void onSoundLoad(SoundLoadEvent event)
|
||||
{
|
||||
event.manager.addSound(mod_pocketDim.modid + ":monk.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":crack.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":tearing.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":rift.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":riftStart.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":riftEnd.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":riftClose.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":riftDoor.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid + ":creepy.ogg");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@ForgeSubscribe
|
||||
public void onSoundEffectResult(PlayBackgroundMusicEvent event)
|
||||
{
|
||||
if (FMLClientHandler.instance().getClient().thePlayer.worldObj.provider.dimensionId == mod_pocketDim.properties.LimboDimensionID)
|
||||
;
|
||||
{
|
||||
event.newGen = new DDNetherFortressGenerator();
|
||||
this.playMusicForDim(FMLClientHandler.instance().getClient().thePlayer.worldObj);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@ForgeSubscribe
|
||||
public void onSoundLoad(SoundLoadEvent event)
|
||||
{
|
||||
event.manager.addSound(mod_pocketDim.modid+":monk.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":crack.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":tearing.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":rift.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":riftStart.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":riftEnd.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":riftClose.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":riftDoor.ogg");
|
||||
event.manager.addSound(mod_pocketDim.modid+":creepy.ogg");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@ForgeSubscribe
|
||||
public void onSoundEffectResult(PlayBackgroundMusicEvent event)
|
||||
{
|
||||
if (FMLClientHandler.instance().getClient().thePlayer.worldObj.provider.dimensionId==mod_pocketDim.properties.LimboDimensionID);
|
||||
{
|
||||
this.playMusicForDim(FMLClientHandler.instance().getClient().thePlayer.worldObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onPlayerEvent(PlayerInteractEvent event)
|
||||
{
|
||||
// Handle placing Vanilla doors on rifts
|
||||
if (!event.entity.worldObj.isRemote)
|
||||
// Handle all door placement here
|
||||
|
||||
World world = event.entity.worldObj;
|
||||
ItemStack stack = event.entityPlayer.inventory.getCurrentItem();
|
||||
if (stack != null)
|
||||
{
|
||||
World world = event.entity.worldObj;
|
||||
ItemStack stack = event.entityPlayer.inventory.getCurrentItem();
|
||||
if (stack != null)
|
||||
if (stack.getItem() instanceof ItemDoor)
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
if (item instanceof ItemDoor)
|
||||
if(mod_pocketDim.itemDimensionalDoor.tryToPlaceDoor(stack, event.entityPlayer, world, event.x, event.y, event.z, event.face))
|
||||
{
|
||||
Block doorToPlace = null;
|
||||
if (stack.itemID == Item.doorIron.itemID)
|
||||
{
|
||||
doorToPlace = mod_pocketDim.dimensionalDoor;
|
||||
}
|
||||
else if (stack.itemID == Item.doorWood.itemID)
|
||||
{
|
||||
doorToPlace = mod_pocketDim.warpDoor;
|
||||
}
|
||||
else if (stack.itemID == mod_pocketDim.itemGoldenDoor.itemID)
|
||||
{
|
||||
doorToPlace = mod_pocketDim.goldenDimensionalDoor;
|
||||
}
|
||||
|
||||
if (doorToPlace != null)
|
||||
{
|
||||
// SenseiKiwi: Why do we have a condition like this? And the event isn't cancelled if we take the else portion.
|
||||
// Comments would have been very helpful.
|
||||
if (mod_pocketDim.itemDimensionalDoor.tryPlacingDoor(doorToPlace, world, event.entityPlayer, stack))
|
||||
{
|
||||
if (!event.entityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
event.setCanceled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseItemDoor.tryItemUse(doorToPlace, stack, event.entityPlayer, world, event.x, event.y, event.z, event.face, true, true);
|
||||
}
|
||||
}
|
||||
//cancel the event so we dont get two doors from vanilla doors
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldLoad(WorldEvent.Load event)
|
||||
{
|
||||
// We need to initialize PocketManager here because onServerAboutToStart fires before we can
|
||||
// use DimensionManager and onServerStarting fires after the game tries to generate terrain.
|
||||
// If a gateway tries to generate before PocketManager has initialized, we get a crash.
|
||||
if (!PocketManager.isLoaded())
|
||||
{
|
||||
PocketManager.load();
|
||||
}
|
||||
|
||||
if (event.world != null)
|
||||
{
|
||||
this.playMusicForDim(event.world);
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onPlayerFall(LivingFallEvent event)
|
||||
{
|
||||
event.setCanceled(event.entity.worldObj.provider.dimensionId == properties.LimboDimensionID);
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
public boolean onDeathWithHighPriority(LivingDeathEvent event)
|
||||
{
|
||||
// Teleport the entity to Limbo if it's a player in a pocket dimension and
|
||||
// if Limbo preserves player inventories. We'll check again in a low-priority event handler
|
||||
// to give other mods a chance to save the player if Limbo does _not_ preserve inventories.
|
||||
|
||||
Entity entity = event.entity;
|
||||
|
||||
if (entity instanceof EntityPlayer && properties.LimboEnabled &&
|
||||
entity.worldObj.provider instanceof PocketProvider && properties.LimboReturnsInventoryEnabled)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
mod_pocketDim.deathTracker.addUsername(player.username);
|
||||
revivePlayerInLimbo(player);
|
||||
event.setCanceled(true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.LOWEST)
|
||||
public boolean onDeathWithLowPriority(LivingDeathEvent event)
|
||||
{
|
||||
// This low-priority handler gives mods a chance to save a player from death before we apply
|
||||
// teleporting them to Limbo _without_ preserving their inventory. We also check if the player
|
||||
// died in a pocket dimension and record it, regardless of whether the player will be sent to Limbo.
|
||||
|
||||
Entity entity = event.entity;
|
||||
|
||||
if (entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
mod_pocketDim.deathTracker.addUsername(player.username);
|
||||
}
|
||||
|
||||
if (properties.LimboEnabled && !properties.LimboReturnsInventoryEnabled)
|
||||
{
|
||||
player.inventory.clearInventory(-1, -1);
|
||||
revivePlayerInLimbo(player);
|
||||
event.setCanceled(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void revivePlayerInLimbo(EntityPlayer player)
|
||||
{
|
||||
player.extinguish();
|
||||
@ForgeSubscribe
|
||||
public void onWorldLoad(WorldEvent.Load event)
|
||||
{
|
||||
// We need to initialize PocketManager here because onServerAboutToStart
|
||||
// fires before we can
|
||||
// use DimensionManager and onServerStarting fires after the game tries
|
||||
// to generate terrain.
|
||||
// If a gateway tries to generate before PocketManager has initialized,
|
||||
// we get a crash.
|
||||
if (!PocketManager.isLoaded())
|
||||
{
|
||||
PocketManager.load();
|
||||
}
|
||||
|
||||
if (event.world != null)
|
||||
{
|
||||
this.playMusicForDim(event.world);
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onPlayerFall(LivingFallEvent event)
|
||||
{
|
||||
event.setCanceled(event.entity.worldObj.provider.dimensionId == properties.LimboDimensionID);
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
public boolean onDeathWithHighPriority(LivingDeathEvent event)
|
||||
{
|
||||
// Teleport the entity to Limbo if it's a player in a pocket dimension
|
||||
// and
|
||||
// if Limbo preserves player inventories. We'll check again in a
|
||||
// low-priority event handler
|
||||
// to give other mods a chance to save the player if Limbo does _not_
|
||||
// preserve inventories.
|
||||
|
||||
Entity entity = event.entity;
|
||||
|
||||
if (entity instanceof EntityPlayer && properties.LimboEnabled && entity.worldObj.provider instanceof PocketProvider
|
||||
&& properties.LimboReturnsInventoryEnabled)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
mod_pocketDim.deathTracker.addUsername(player.username);
|
||||
revivePlayerInLimbo(player);
|
||||
event.setCanceled(true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.LOWEST)
|
||||
public boolean onDeathWithLowPriority(LivingDeathEvent event)
|
||||
{
|
||||
// This low-priority handler gives mods a chance to save a player from
|
||||
// death before we apply
|
||||
// teleporting them to Limbo _without_ preserving their inventory. We
|
||||
// also check if the player
|
||||
// died in a pocket dimension and record it, regardless of whether the
|
||||
// player will be sent to Limbo.
|
||||
|
||||
Entity entity = event.entity;
|
||||
|
||||
if (entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
mod_pocketDim.deathTracker.addUsername(player.username);
|
||||
|
||||
if (properties.LimboEnabled && !properties.LimboReturnsInventoryEnabled)
|
||||
{
|
||||
player.inventory.clearInventory(-1, -1);
|
||||
revivePlayerInLimbo(player);
|
||||
event.setCanceled(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void revivePlayerInLimbo(EntityPlayer player)
|
||||
{
|
||||
player.extinguish();
|
||||
player.clearActivePotions();
|
||||
player.setHealth(player.getMaxHealth());
|
||||
Point4D destination = LimboProvider.getLimboSkySpawn(player, properties);
|
||||
DDTeleporter.teleportEntity(player, destination, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldSave(WorldEvent.Save event)
|
||||
{
|
||||
if (event.world.provider.dimensionId == 0)
|
||||
{
|
||||
PocketManager.save();
|
||||
|
||||
if (mod_pocketDim.deathTracker != null && mod_pocketDim.deathTracker.isModified())
|
||||
{
|
||||
mod_pocketDim.deathTracker.writeToFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playMusicForDim(World world)
|
||||
{
|
||||
if (world.isRemote)
|
||||
{
|
||||
SoundManager sndManager = FMLClientHandler.instance().getClient().sndManager;
|
||||
@ForgeSubscribe
|
||||
public void onWorldSave(WorldEvent.Save event)
|
||||
{
|
||||
if (event.world.provider.dimensionId == 0)
|
||||
{
|
||||
PocketManager.save();
|
||||
|
||||
// SenseiKiwi: I've added the following check as a quick fix for a reported crash.
|
||||
// This needs to work without a hitch or we have to stop trying to replace the background music...
|
||||
if (sndManager != null && sndManager.sndSystem != null)
|
||||
{
|
||||
if (world.provider instanceof LimboProvider)
|
||||
{
|
||||
sndManager.sndSystem.stop("BgMusic");
|
||||
SoundPoolEntry soundPoolEntry = sndManager.soundPoolSounds.getRandomSoundFromSoundPool(mod_pocketDim.modid+":creepy");
|
||||
if (soundPoolEntry != null)
|
||||
{
|
||||
sndManager.sndSystem.backgroundMusic("LimboMusic", soundPoolEntry.getSoundUrl(), soundPoolEntry.getSoundName(), false);
|
||||
sndManager.sndSystem.play("LimboMusic");
|
||||
}
|
||||
}
|
||||
else if (!(world.provider instanceof LimboProvider))
|
||||
{
|
||||
sndManager.sndSystem.stop("LimboMusic");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mod_pocketDim.deathTracker != null && mod_pocketDim.deathTracker.isModified())
|
||||
{
|
||||
mod_pocketDim.deathTracker.writeToFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playMusicForDim(World world)
|
||||
{
|
||||
if (world.isRemote)
|
||||
{
|
||||
SoundManager sndManager = FMLClientHandler.instance().getClient().sndManager;
|
||||
|
||||
// SenseiKiwi: I've added the following check as a quick fix for a
|
||||
// reported crash.
|
||||
// This needs to work without a hitch or we have to stop trying to
|
||||
// replace the background music...
|
||||
if (sndManager != null && sndManager.sndSystem != null)
|
||||
{
|
||||
if (world.provider instanceof LimboProvider)
|
||||
{
|
||||
sndManager.sndSystem.stop("BgMusic");
|
||||
SoundPoolEntry soundPoolEntry = sndManager.soundPoolSounds.getRandomSoundFromSoundPool(mod_pocketDim.modid + ":creepy");
|
||||
if (soundPoolEntry != null)
|
||||
{
|
||||
sndManager.sndSystem.backgroundMusic("LimboMusic", soundPoolEntry.getSoundUrl(), soundPoolEntry.getSoundName(), false);
|
||||
sndManager.sndSystem.play("LimboMusic");
|
||||
}
|
||||
}
|
||||
else if (!(world.provider instanceof LimboProvider))
|
||||
{
|
||||
sndManager.sndSystem.stop("LimboMusic");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +1,31 @@
|
|||
package StevenDimDoors.mod_pocketDim.items;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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.Item;
|
||||
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.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
import StevenDimDoors.mod_pocketDim.config.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
|
||||
|
||||
|
||||
public abstract class BaseItemDoor extends ItemDoor
|
||||
{
|
||||
// maps non-dimensional door items to their corresponding dimensional door
|
||||
// item
|
||||
private static HashMap<ItemDoor, BaseItemDoor> vanillaDoorMapping = new HashMap<ItemDoor, BaseItemDoor>();
|
||||
private static DDProperties properties = null;
|
||||
|
||||
public BaseItemDoor(int itemID, Material material)
|
||||
|
@ -29,6 +35,10 @@ public abstract class BaseItemDoor extends ItemDoor
|
|||
this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
|
||||
if (properties == null)
|
||||
properties = DDProperties.instance();
|
||||
|
||||
vanillaDoorMapping.put((ItemDoor) mod_pocketDim.itemGoldenDoor, (BaseItemDoor) mod_pocketDim.itemGoldenDimensionalDoor);
|
||||
vanillaDoorMapping.put((ItemDoor) Item.doorIron, (BaseItemDoor) mod_pocketDim.itemDimensionalDoor);
|
||||
vanillaDoorMapping.put((ItemDoor) Item.doorWood, (BaseItemDoor) mod_pocketDim.itemWarpDoor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,12 +51,86 @@ public abstract class BaseItemDoor extends ItemDoor
|
|||
@Override
|
||||
public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);
|
||||
|
||||
/**
|
||||
* Overriden in subclasses to specify which door block that door item will
|
||||
* place
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract BaseDimDoor getDoortoItemMapping();
|
||||
|
||||
/**
|
||||
* Overriden here to remove vanilla block placement functionality from
|
||||
* dimensional doors, we handle this in the EventHookContainer
|
||||
*/
|
||||
@Override
|
||||
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 side, boolean requireLink, boolean reduceStack)
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
// Only place doors on top of blocks - check if we're targeting the top side
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public static BaseDimDoor getDoorToPlace(Item item)
|
||||
{
|
||||
if (!(item instanceof BaseItemDoor))
|
||||
{
|
||||
item = BaseItemDoor.vanillaDoorMapping.get(item);
|
||||
}
|
||||
return ((BaseItemDoor) item).getDoortoItemMapping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to place a door block, called in EventHookContainer
|
||||
*
|
||||
* @param doorBlock
|
||||
* @param stack
|
||||
* @param player
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param side
|
||||
* @param requireLink
|
||||
* @param reduceStack
|
||||
* @return
|
||||
*/
|
||||
public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side)
|
||||
{
|
||||
if (world.isRemote)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(stack.getItem() instanceof ItemDoor))
|
||||
{
|
||||
throw new IllegalArgumentException("The itemstack must correspond to some type of door");
|
||||
}
|
||||
if (BaseItemDoor.placeDoorOnBlock(getDoorToPlace(stack.getItem()), stack, player, world, x, y, z, side))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return BaseItemDoor.placeDoorOnRift(getDoorToPlace(stack.getItem()), world, player, stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* try to place a door block on a block
|
||||
* @param doorBlock
|
||||
* @param stack
|
||||
* @param player
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param side
|
||||
* @return
|
||||
*/
|
||||
public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side)
|
||||
{
|
||||
if (world.isRemote)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 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);
|
||||
|
@ -58,14 +142,13 @@ public abstract class BaseItemDoor extends ItemDoor
|
|||
}
|
||||
}
|
||||
|
||||
if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) &&
|
||||
player.canPlayerEdit(x, y, z, side, stack) && player.canPlayerEdit(x, y + 1, z, side, stack) &&
|
||||
(!requireLink || PocketManager.getLink(x, y + 1, z, world) != null)&&stack.stackSize>0)
|
||||
if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && player.canPlayerEdit(x, y, z, side, stack)
|
||||
&& player.canPlayerEdit(x, y + 1, z, side, stack) && stack.stackSize > 0)
|
||||
{
|
||||
int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
|
||||
placeDoorBlock(world, x, y, z, orientation, doorBlock);
|
||||
|
||||
if (!player.capabilities.isCreativeMode && reduceStack)
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
|
@ -75,17 +158,23 @@ public abstract class BaseItemDoor extends ItemDoor
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player);
|
||||
|
||||
public boolean tryPlacingDoor(Block doorBlock, World world, EntityPlayer player, ItemStack item)
|
||||
/**
|
||||
* uses a raytrace to try and place a door on a rift
|
||||
*
|
||||
* @param doorBlock
|
||||
* @param world
|
||||
* @param player
|
||||
* @param stack
|
||||
* @return
|
||||
*/
|
||||
public static boolean placeDoorOnRift(Block doorBlock, World world, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
if (world.isRemote)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MovingObjectPosition hit = getMovingObjectPositionFromPlayer(player.worldObj, player, true);
|
||||
MovingObjectPosition hit = BaseItemDoor.doRayTrace(player.worldObj, player, true);
|
||||
if (hit != null)
|
||||
{
|
||||
if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID)
|
||||
|
@ -97,15 +186,19 @@ public abstract class BaseItemDoor extends ItemDoor
|
|||
int y = hit.blockY;
|
||||
int z = hit.blockZ;
|
||||
|
||||
if (player.canPlayerEdit(x, y, z, hit.sideHit, item) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, item))
|
||||
if (player.canPlayerEdit(x, y, z, hit.sideHit, stack) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, stack))
|
||||
{
|
||||
if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z))
|
||||
{
|
||||
int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
|
||||
placeDoorBlock(world, x, y - 1, z, orientation, doorBlock);
|
||||
if(!(item.getItem() instanceof BaseItemDoor))
|
||||
if (!(stack.getItem() instanceof BaseItemDoor))
|
||||
{
|
||||
((TileEntityDimDoor)world.getBlockTileEntity(x, y, z)).hasGennedPair=true;
|
||||
((TileEntityDimDoor) world.getBlockTileEntity(x, y, z)).hasGennedPair = true;
|
||||
}
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -122,4 +215,38 @@ public abstract class BaseItemDoor extends ItemDoor
|
|||
|
||||
return (id == properties.RiftBlockID || id == 0 || Block.blocksList[id].blockMaterial.isReplaceable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from minecraft Item.class
|
||||
* TODO we probably can improve this
|
||||
*
|
||||
* @param par1World
|
||||
* @param par2EntityPlayer
|
||||
* @param par3
|
||||
* @return
|
||||
*/
|
||||
protected static MovingObjectPosition doRayTrace(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
|
||||
{
|
||||
float f = 1.0F;
|
||||
float f1 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * f;
|
||||
float f2 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * f;
|
||||
double d0 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double) f;
|
||||
double d1 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double) f
|
||||
+ (double) (par1World.isRemote ? par2EntityPlayer.getEyeHeight() - par2EntityPlayer.getDefaultEyeHeight() : par2EntityPlayer.getEyeHeight());
|
||||
double d2 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double) f;
|
||||
Vec3 vec3 = par1World.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
|
||||
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
|
||||
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
|
||||
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
||||
float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
double d3 = 5.0D;
|
||||
if (par2EntityPlayer instanceof EntityPlayerMP)
|
||||
{
|
||||
d3 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance();
|
||||
}
|
||||
Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
|
||||
return par1World.rayTraceBlocks_do_do(vec3, vec31, par3, !par3);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
|
||||
public class ItemDimensionalDoor extends BaseItemDoor
|
||||
{
|
||||
|
@ -26,23 +27,8 @@ public class ItemDimensionalDoor extends BaseItemDoor
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
protected BaseDimDoor getDoortoItemMapping()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (tryPlacingDoor(mod_pocketDim.dimensionalDoor, world, player, stack) &&
|
||||
!player.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y,
|
||||
int z, int par7, float par8, float par9, float par10)
|
||||
{
|
||||
return tryItemUse(mod_pocketDim.dimensionalDoor, stack, player, world, x, y, z, par7, false, true);
|
||||
return (BaseDimDoor) mod_pocketDim.dimensionalDoor;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
|
||||
public class ItemGoldDimDoor extends BaseItemDoor
|
||||
{
|
||||
|
@ -16,7 +17,6 @@ public class ItemGoldDimDoor extends BaseItemDoor
|
|||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||
|
@ -27,26 +27,8 @@ public class ItemGoldDimDoor extends BaseItemDoor
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y,
|
||||
int z, int par7, float par8, float par9, float par10)
|
||||
protected BaseDimDoor getDoortoItemMapping()
|
||||
{
|
||||
return tryItemUse(mod_pocketDim.goldenDimensionalDoor, stack, player, world, x, y, z, par7, false, true);
|
||||
return (BaseDimDoor) mod_pocketDim.goldenDimensionalDoor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (tryPlacingDoor(mod_pocketDim.goldenDimensionalDoor, world, player, stack) &&
|
||||
!player.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
|
||||
public class ItemUnstableDoor extends BaseItemDoor
|
||||
{
|
||||
|
@ -23,23 +24,8 @@ public class ItemUnstableDoor extends BaseItemDoor
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
protected BaseDimDoor getDoortoItemMapping()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (tryPlacingDoor(mod_pocketDim.unstableDoor, world, player, stack) &&
|
||||
!player.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y,
|
||||
int z, int par7, float par8, float par9, float par10)
|
||||
{
|
||||
return tryItemUse(mod_pocketDim.unstableDoor, stack, player, world, x, y, z, par7, false, true);
|
||||
return (BaseDimDoor) mod_pocketDim.unstableDoor;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
|
||||
|
||||
public class ItemWarpDoor extends BaseItemDoor
|
||||
{
|
||||
|
@ -26,23 +27,8 @@ public class ItemWarpDoor extends BaseItemDoor
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
protected BaseDimDoor getDoortoItemMapping()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (tryPlacingDoor(mod_pocketDim.warpDoor, world, player, stack) &&
|
||||
!player.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.stackSize--;
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y,
|
||||
int z, int par7, float par8, float par9, float par10)
|
||||
{
|
||||
return tryItemUse(mod_pocketDim.warpDoor, stack, player, world, x, y, z, par7, false, true);
|
||||
return (BaseDimDoor) mod_pocketDim.warpDoor;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -243,43 +244,58 @@ public class DDSaveHandler
|
|||
// Create the data directory for our dimensions
|
||||
// Don't catch exceptions here. If we can't create this folder,
|
||||
// the mod should crash to let the user know early on.
|
||||
|
||||
//I still dont think that this is the best way to do this, but atleast it is better than
|
||||
//risking deleting everything. I delete files afterwards that I did not modify.
|
||||
|
||||
String basePath = DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/data/";
|
||||
File basePathFile = new File(basePath);
|
||||
Files.createParentDirs(basePathFile);
|
||||
basePathFile.mkdir();
|
||||
|
||||
//get the save directory path
|
||||
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/data/");
|
||||
|
||||
//create the save directory
|
||||
Files.createParentDirs(saveDirectory);
|
||||
saveDirectory.mkdir();
|
||||
|
||||
//create and write the blackList
|
||||
BlacklistProcessor blacklistReader = new BlacklistProcessor();
|
||||
writeBlacklist(blacklist, blacklistReader,basePath);
|
||||
writeBlacklist(blacklist, blacklistReader,saveDirectory);
|
||||
|
||||
FileFilter dataFileFilter = new FileFilters.RegexFileFilter("dim_-?\\d+\\.txt");
|
||||
|
||||
//TODO Deal with temp files correctly
|
||||
File[] dataFiles = basePathFile.listFiles(dataFileFilter);
|
||||
//Take the list of all dimData files already saved in the save Directory, and map them according to ID.
|
||||
File[] dataFiles = saveDirectory.listFiles(dataFileFilter);
|
||||
HashMap<Integer,File> unsavedDimData = new HashMap<Integer,File>();
|
||||
for (File dataFile : dataFiles)
|
||||
{
|
||||
dataFile.delete();
|
||||
unsavedDimData.put(Integer.parseInt(dataFile.getName().split("[.]")[0].substring(4)), dataFile);
|
||||
}
|
||||
|
||||
|
||||
basePathFile = null;
|
||||
basePath += "dim_";
|
||||
|
||||
boolean succeeded = true;
|
||||
|
||||
//write the dimension save data, and remove the ones we save from the mapping
|
||||
DimDataProcessor writer = new DimDataProcessor();
|
||||
for (IPackable<PackedDimData> dimension : dimensions)
|
||||
{
|
||||
succeeded &= writeDimension(dimension, writer, basePath);
|
||||
succeeded &= writeDimension(dimension, writer, saveDirectory.getAbsolutePath()+"/dim_");
|
||||
unsavedDimData.remove(Integer.parseInt(dimension.name()));
|
||||
}
|
||||
|
||||
//once we have finished saving, delete the files from the save directory that where not saved
|
||||
if(succeeded)
|
||||
{
|
||||
for (File dataFile : unsavedDimData.values())
|
||||
{
|
||||
dataFile.delete();
|
||||
}
|
||||
}
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
private static boolean writeBlacklist(List<Integer> blacklist, BlacklistProcessor writer, String basePath)
|
||||
private static boolean writeBlacklist(List<Integer> blacklist, BlacklistProcessor writer, File saveDirectory)
|
||||
{
|
||||
try
|
||||
{
|
||||
File tempFile = new File(basePath + "blacklist.tmp");
|
||||
File saveFile = new File(basePath + "blacklist.txt");
|
||||
File tempFile = new File(saveDirectory.getAbsolutePath() + "blacklist.tmp");
|
||||
File saveFile = new File(saveDirectory.getAbsolutePath() + "blacklist.txt");
|
||||
writer.writeToFile(tempFile, blacklist);
|
||||
saveFile.delete();
|
||||
tempFile.renameTo(saveFile);
|
||||
|
|
Loading…
Add table
Reference in a new issue