2013-02-18 03:46:16 +01:00
|
|
|
package StevenDimDoors.mod_pocketDim;
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-03-22 05:58:55 +01:00
|
|
|
import java.io.File;
|
2013-02-18 03:46:16 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
|
|
|
|
2013-05-27 14:10:07 +02:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2013-03-22 05:58:55 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2013-04-01 09:15:16 +02:00
|
|
|
import net.minecraft.block.Block;
|
2013-03-22 05:58:55 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2013-02-18 03:46:16 +01:00
|
|
|
import net.minecraft.entity.EntityLiving;
|
|
|
|
import net.minecraft.entity.monster.EntityEnderman;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.EnumMovingObjectType;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.World;
|
2013-04-01 09:15:16 +02:00
|
|
|
import net.minecraft.world.WorldServer;
|
2013-03-22 05:58:55 +01:00
|
|
|
import net.minecraftforge.client.event.sound.SoundLoadEvent;
|
2013-02-18 03:46:16 +01:00
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
public class EventHookContainer
|
|
|
|
{
|
2013-06-14 01:01:54 +02:00
|
|
|
private static Random rand = new Random();
|
|
|
|
private static DDProperties properties = null;
|
|
|
|
|
|
|
|
public EventHookContainer()
|
|
|
|
{
|
|
|
|
if (properties == null)
|
|
|
|
properties = DDProperties.instance();
|
|
|
|
}
|
2013-03-22 05:58:55 +01:00
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-05-27 14:10:07 +02:00
|
|
|
|
2013-03-22 05:58:55 +01:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void onSoundLoad(SoundLoadEvent event)
|
|
|
|
{
|
|
|
|
File dataDir = Minecraft.getMinecraft().mcDataDir;
|
|
|
|
|
2013-05-31 08:17:05 +02:00
|
|
|
event.manager.soundPoolSounds.addSound("mods/DimDoors/sfx/monk.ogg", (mod_pocketDim.class.getResource("/mods/DimDoors/sfx/monk.ogg")));
|
|
|
|
event.manager.soundPoolSounds.addSound("mods/DimDoors/sfx/crack.ogg", (mod_pocketDim.class.getResource("/mods/DimDoors/sfx/crack.ogg")));
|
|
|
|
event.manager.soundPoolSounds.addSound("mods/DimDoors/sfx/tearing.ogg", (mod_pocketDim.class.getResource("/mods/DimDoors/sfx/tearing.ogg")));
|
2013-03-22 05:58:55 +01:00
|
|
|
}
|
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
@ForgeSubscribe
|
|
|
|
public void onWorldLoad(WorldEvent.Load event)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!mod_pocketDim.hasInitDims&&event.world.provider.dimensionId==0&&!event.world.isRemote)
|
|
|
|
{
|
2013-03-29 02:34:38 +01:00
|
|
|
System.out.println("Registering Pocket Dims");
|
|
|
|
mod_pocketDim.hasInitDims=true;
|
2013-02-18 03:46:16 +01:00
|
|
|
dimHelper.instance.unregsisterDims();
|
|
|
|
dimHelper.dimList.clear();
|
|
|
|
dimHelper.instance.interDimLinkList.clear();
|
|
|
|
dimHelper.instance.initPockets();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-07 06:37:13 +02:00
|
|
|
for(Integer ids : dimHelper.getIDs())
|
2013-04-01 09:15:16 +02:00
|
|
|
{
|
2013-04-07 06:37:13 +02:00
|
|
|
World world = dimHelper.getWorld(ids);
|
2013-04-01 09:15:16 +02:00
|
|
|
int linkCount=0;
|
|
|
|
|
|
|
|
if(dimHelper.dimList.containsKey(world.provider.dimensionId))
|
|
|
|
{
|
|
|
|
|
|
|
|
for(LinkData link:dimHelper.dimList.get(world.provider.dimensionId).printAllLinkData())
|
|
|
|
{
|
|
|
|
if(linkCount>100)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
linkCount++;
|
|
|
|
int blocktoReplace = world.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord);
|
2013-05-29 21:45:21 +02:00
|
|
|
if(!mod_pocketDim.blocksImmuneToRift.contains(blocktoReplace))
|
2013-04-01 09:15:16 +02:00
|
|
|
{
|
2013-06-14 01:01:54 +02:00
|
|
|
dimHelper.getWorld(link.locDimID).setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID);
|
2013-04-01 09:15:16 +02:00
|
|
|
}
|
2013-04-01 10:04:59 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
|
2013-04-01 09:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent event)
|
|
|
|
{
|
|
|
|
if(event.entity instanceof EntityPlayer)
|
|
|
|
{
|
|
|
|
// System.out.println(event.entity.worldObj.provider.dimensionId);
|
|
|
|
|
|
|
|
// PacketDispatcher.sendPacketToPlayer(DimUpdatePacket.sendPacket(event.world.provider.dimensionId,1),(Player) event.entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onPlayerFall(LivingFallEvent event)
|
|
|
|
{
|
|
|
|
|
2013-06-14 01:01:54 +02:00
|
|
|
event.setCanceled(event.entity.worldObj.provider.dimensionId==properties.LimboDimensionID);
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onPlayerInteract(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-09 23:16:27 +02:00
|
|
|
/**
|
2013-02-18 03:46:16 +01:00
|
|
|
|
2013-06-14 01:01:54 +02:00
|
|
|
if(event.entityPlayer.worldObj.provider.dimensionId==properties.LimboDimensionID&&event.action==PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
|
2013-04-07 06:37:13 +02:00
|
|
|
{
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
|
2013-04-07 06:37:13 +02:00
|
|
|
int x = event.x;
|
|
|
|
int y = event.y;
|
|
|
|
|
|
|
|
int z = event.z;
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-07 06:37:13 +02:00
|
|
|
if(event.entityPlayer.getHeldItem()!=null)
|
|
|
|
{
|
|
|
|
if(event.entityPlayer.getHeldItem().getItem() instanceof ItemBlock)
|
|
|
|
{
|
|
|
|
// if(event.entityPlayer instanceof EntityPlayerMP)
|
|
|
|
{
|
|
|
|
|
|
|
|
Point3D point = new Point3D(x,y,z);
|
|
|
|
dimHelper.blocksToDecay.add(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
|
2013-04-07 06:37:13 +02:00
|
|
|
}
|
2013-05-09 23:16:27 +02:00
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-05-09 23:16:27 +02:00
|
|
|
**/
|
2013-02-18 03:46:16 +01:00
|
|
|
|
2013-04-07 06:37:13 +02:00
|
|
|
}
|
|
|
|
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ForgeSubscribe
|
|
|
|
public void onPlayerEvent(PlayerEvent event)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
if(!event.entity.worldObj.isRemote)
|
|
|
|
{
|
|
|
|
ItemStack item = event.entityPlayer.inventory.getCurrentItem();
|
|
|
|
if(item!=null)
|
|
|
|
{
|
|
|
|
if(item.getItem() instanceof ItemRiftBlade)
|
|
|
|
{
|
|
|
|
List<EntityLiving> list = event.entity.worldObj.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox( event.entityPlayer.posX-7,event.entityPlayer.posY-7, event.entityPlayer.posZ-7, event.entityPlayer.posX+7,event.entityPlayer.posY+7, event.entityPlayer.posZ+7));
|
|
|
|
list.remove(event.entity);
|
|
|
|
|
|
|
|
|
|
|
|
for(EntityLiving ent : list)
|
|
|
|
{
|
|
|
|
|
|
|
|
Vec3 var3 = event.entityPlayer.getLook(1.0F).normalize();
|
|
|
|
Vec3 var4 = event.entityPlayer.worldObj.getWorldVec3Pool().getVecFromPool(ent.posX - event.entityPlayer.posX, ent.boundingBox.minY + (double)((ent.height) / 2.0F) - ( event.entityPlayer.posY + (double) event.entityPlayer.getEyeHeight()), ent.posZ - event.entityPlayer.posZ);
|
|
|
|
double var5 = var4.lengthVector();
|
|
|
|
var4 = var4.normalize();
|
|
|
|
double var7 = var3.dotProduct(var4);
|
|
|
|
if( (var7+.1) > 1.0D - 0.025D / var5 ? event.entityPlayer.canEntityBeSeen(ent) : false)
|
|
|
|
{
|
|
|
|
System.out.println(list.size());
|
|
|
|
ItemRiftBlade.class.cast(item.getItem()).teleportToEntity(item,ent, event.entityPlayer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
//ItemRiftBlade.class.cast(item.getItem()).teleportTo(event.entityPlayer, ent.posX, ent.posY, ent.posZ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
**/
|
|
|
|
}
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onPlayerDrops(PlayerDropsEvent event)
|
|
|
|
{
|
2013-04-07 06:37:13 +02:00
|
|
|
mod_pocketDim.limboSpawnInventory.put(event.entityPlayer.username, event.drops);
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onWorldunload(WorldEvent.Unload event)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void onWorldsave(WorldEvent.Save event)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(mod_pocketDim.hasInitDims&&event.world.provider.dimensionId==0)
|
|
|
|
{
|
|
|
|
dimHelper.instance.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|