Search in sources :

Example 6 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project MinecraftForge by MinecraftForge.

the class CustomSpriteTest method textureStitch.

@SubscribeEvent
public void textureStitch(TextureStitchEvent.Pre event) {
    DelegateSprite bottom = DelegateSprite.make("bottom", new ResourceLocation("textures/blocks/diamond_block.png"));
    DelegateSprite top = DelegateSprite.make("top", new ResourceLocation("textures/blocks/tnt_side.png"));
    TextureMap textureMap = event.getMap();
    textureMap.setTextureEntry(bottom);
    textureMap.setTextureEntry(top);
}
Also used : TextureMap(net.minecraft.client.renderer.texture.TextureMap) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsClient method onDrawBlockHighlightEventFirst.

@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onDrawBlockHighlightEventFirst(DrawBlockHighlightEvent event) {
    BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
    if (pos != null) {
        PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(Minecraft.getMinecraft().theWorld, pos);
        if (wrapper != null && wrapper.wrapping != null && wrapper.wrapping.renderer != null && wrapper.wrapping.centerCoord != null) {
            //				GL11.glPushMatrix();
            float partialTicks = event.getPartialTicks();
            Entity player = Minecraft.getMinecraft().thePlayer;
            wrapper.wrapping.renderer.setupTranslation(partialTicks);
            Tessellator tessellator = Tessellator.getInstance();
            VertexBuffer vertexbuffer = tessellator.getBuffer();
            double xOff = (player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks) - wrapper.wrapping.renderer.offsetPos.getX();
            double yOff = (player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks) - wrapper.wrapping.renderer.offsetPos.getY();
            double zOff = (player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks) - wrapper.wrapping.renderer.offsetPos.getZ();
            vertexbuffer.xOffset += xOff;
            vertexbuffer.yOffset += yOff;
            vertexbuffer.zOffset += zOff;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsCommon method onPlayerTickEvent.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerTickEvent(PlayerTickEvent event) {
    if (!event.player.worldObj.isRemote && event.player != null) {
        EntityPlayerMP p = (EntityPlayerMP) event.player;
        try {
            if (!(p.connection instanceof CustomNetHandlerPlayServer)) {
                p.connection = new CustomNetHandlerPlayServer(p.connection);
            } else {
                CustomNetHandlerPlayServer customNetHandler = (CustomNetHandlerPlayServer) p.connection;
                if (p.interactionManager.getBlockReachDistance() == CustomNetHandlerPlayServer.dummyBlockReachDist && customNetHandler.ticksSinceLastTry == 2) {
                    p.interactionManager.setBlockReachDistance(((CustomNetHandlerPlayServer) p.connection).lastGoodBlockReachDist);
                }
                customNetHandler.ticksSinceLastTry++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Double[] pos = lastPositions.get(p);
        if (pos == null) {
            pos = new Double[3];
            lastPositions.put(p, pos);
        }
        try {
            if (pos[0] != p.posX || pos[2] != p.posZ) {
                // Player has moved
                if (Math.abs(p.posX) > 27000000 || Math.abs(p.posZ) > 27000000) {
                    // Player is outside of world border, tp them back
                    p.attemptTeleport(pos[0], pos[1], pos[2]);
                    p.addChatMessage(new TextComponentString("You can't go beyond 27000000 blocks because airships are stored there!"));
                }
            }
        } catch (NullPointerException e) {
            ValkyrienWarfareMod.VWLogger.log(Level.WARNING, "Nullpointer EventsCommon.java:onPlayerTickEvent");
        }
        pos[0] = p.posX;
        pos[1] = p.posY;
        pos[2] = p.posZ;
    }
}
Also used : CustomNetHandlerPlayServer(ValkyrienWarfareBase.Interaction.CustomNetHandlerPlayServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsCommon method onRightClick.

@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getWorld().isRemote) {
        PhysicsWrapperEntity physObj = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(event.getWorld(), event.getPos());
        if (physObj != null) {
            //Bucket fix, probably not that important
            if (event.getEntityPlayer().getHeldItem(event.getHand()) != null && event.getEntityPlayer().getHeldItem(event.getHand()).getItem() instanceof ItemBucket) {
                event.setResult(Result.ALLOW);
                event.setCanceled(false);
            }
            if (ValkyrienWarfareMod.runAirshipPermissions && !(physObj.wrapping.creator.equals(event.getEntityPlayer().entityUniqueID.toString()) || physObj.wrapping.allowedUsers.contains(event.getEntityPlayer().entityUniqueID.toString()))) {
                event.getEntityPlayer().addChatMessage(new TextComponentString("You need to be added to the airship to do that!" + (physObj.wrapping.creator == null || physObj.wrapping.creator.trim().isEmpty() ? " Try using \"/airshipSettings claim\"!" : "")));
                event.setCanceled(true);
                return;
            }
        }
    }
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) ItemBucket(net.minecraft.item.ItemBucket) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsCommon method onWorldLoad.

/**@SubscribeEvent(priority = EventPriority.HIGHEST)
	public void onExplosionDetonateEvent(ExplosionEvent.Detonate event) {
		Explosion e = event.getExplosion();

		double xx = e.explosionX, yy = e.explosionY, zz = e.explosionZ;
		List<BlockPos> affectedPositionsList = new ArrayList<BlockPos>(e.getAffectedBlockPositions());
		Map<EntityPlayer, Vec3d> playerKnockbackMap = new HashMap<EntityPlayer, Vec3d>(e.getPlayerKnockbackMap());

		Vector center = new Vector(e.explosionX, e.explosionY, e.explosionZ);
		World worldIn = e.worldObj;
		float radius = e.explosionSize;

		AxisAlignedBB toCheck = new AxisAlignedBB(center.X - radius, center.Y - radius, center.Z - radius, center.X + radius, center.Y + radius, center.Z + radius);
		List<PhysicsWrapperEntity> shipsNear = ValkyrienWarfareMod.physicsManager.getManagerForWorld(e.worldObj).getNearbyPhysObjects(toCheck);
		// e.doExplosionA();
		// TODO: Make this compatible and shit!
		Field[] fields = getFields(e);

		for (PhysicsWrapperEntity ship : shipsNear) {
			Vector inLocal = new Vector(center);
			RotationMatrices.applyTransform(ship.wrapping.coordTransform.wToLTransform, inLocal);
			// inLocal.roundToWhole();

			// Explosion expl = new Explosion(ship.worldObj, null, inLocal.X, inLocal.Y, inLocal.Z, radius, false, false);

			Explosion expl = e;

			if (setExplosionPosition(e, inLocal.X, inLocal.Y, inLocal.Z, fields)) {

				double waterRange = .6D;

				boolean cancelDueToWater = false;

				for (int x = (int) Math.floor(expl.explosionX - waterRange); x <= Math.ceil(expl.explosionX + waterRange); x++) {
					for (int y = (int) Math.floor(expl.explosionY - waterRange); y <= Math.ceil(expl.explosionY + waterRange); y++) {
						for (int z = (int) Math.floor(expl.explosionZ - waterRange); z <= Math.ceil(expl.explosionZ + waterRange); z++) {
							if (!cancelDueToWater) {
								IBlockState state = e.worldObj.getBlockState(new BlockPos(x, y, z));
								if (state.getBlock() instanceof BlockLiquid) {
									cancelDueToWater = true;
								}
							}
						}
					}
				}

				expl.doExplosionA();

				double affectedPositions = 0D;

				for (Object o : expl.affectedBlockPositions) {
					BlockPos pos = (BlockPos) o;
					IBlockState state = ship.worldObj.getBlockState(pos);
					Block block = state.getBlock();
					if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
						affectedPositions++;
					}
				}

				if (!cancelDueToWater) {
					for (Object o : expl.affectedBlockPositions) {
						BlockPos pos = (BlockPos) o;

						IBlockState state = ship.worldObj.getBlockState(pos);
						Block block = state.getBlock();
						if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
							if (block.canDropFromExplosion(expl)) {
								block.dropBlockAsItemWithChance(ship.worldObj, pos, state, 1.0F / expl.explosionSize, 0);
							}
							block.onBlockExploded(ship.worldObj, pos, expl);
							if (!worldIn.isRemote) {
								Vector posVector = new Vector(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5);

								ship.wrapping.coordTransform.fromLocalToGlobal(posVector);

								double mass = BlockMass.basicMass.getMassFromState(state, pos, ship.worldObj);

								double explosionForce = Math.sqrt(e.explosionSize) * 1000D * mass;

								Vector forceVector = new Vector(pos.getX() + .5 - expl.explosionX, pos.getY() + .5 - expl.explosionY, pos.getZ() + .5 - expl.explosionZ);

								double vectorDist = forceVector.length();

								forceVector.normalize();

								forceVector.multiply(explosionForce / vectorDist);

								RotationMatrices.doRotationOnly(ship.wrapping.coordTransform.lToWRotation, forceVector);

								PhysicsQueuedForce queuedForce = new PhysicsQueuedForce(forceVector, posVector, false, 1);

								if (!ship.wrapping.explodedPositionsThisTick.contains(pos)) {
									ship.wrapping.explodedPositionsThisTick.add(pos);
								}

								ship.wrapping.queueForce(queuedForce);
							}
						}
					}
				}

			}
			e.getAffectedBlockPositions().clear();
			e.getAffectedBlockPositions().addAll(affectedPositionsList);
			e.getPlayerKnockbackMap().clear();
			e.getPlayerKnockbackMap().putAll(playerKnockbackMap);

		}
	}**/
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onWorldLoad(WorldEvent.Load event) {
    World world = event.getWorld();
    ValkyrienWarfareMod.physicsManager.initWorld(world);
    world.addEventListener(new ValkyrienWarfareWorldEventListener(world));
}
Also used : ValkyrienWarfareWorldEventListener(ValkyrienWarfareBase.Interaction.ValkyrienWarfareWorldEventListener) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1135 ItemStack (net.minecraft.item.ItemStack)316 EntityPlayer (net.minecraft.entity.player.EntityPlayer)314 World (net.minecraft.world.World)196 BlockPos (net.minecraft.util.math.BlockPos)179 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)136 IBlockState (net.minecraft.block.state.IBlockState)120 ResourceLocation (net.minecraft.util.ResourceLocation)102 Entity (net.minecraft.entity.Entity)93 Block (net.minecraft.block.Block)86 EntityLivingBase (net.minecraft.entity.EntityLivingBase)84 Minecraft (net.minecraft.client.Minecraft)72 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)66 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)64 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)55 Item (net.minecraft.item.Item)53 EntityItem (net.minecraft.entity.item.EntityItem)48 TileEntity (net.minecraft.tileentity.TileEntity)46 TextComponentString (net.minecraft.util.text.TextComponentString)42 Random (java.util.Random)37