Some Build world, support for far rendered particles

This commit is contained in:
Shaun Bennett 2015-05-03 14:41:09 -05:00
parent 11b36e6b44
commit ff6da92fb7
10 changed files with 313 additions and 60 deletions

View File

@ -0,0 +1,175 @@
package net.minecraft.server.v1_7_R4;
import java.io.IOException;
import java.util.HashMap;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketDataSerializer;
import net.minecraft.server.v1_7_R4.PacketListener;
import net.minecraft.server.v1_7_R4.PacketPlayOutListener;
public class PacketPlayOutWorldParticles extends Packet {
private String a;
private float b;
private float c;
private float d;
private float e;
private float f;
private float g;
private float h;
private int i;
private boolean _displayFar;
public PacketPlayOutWorldParticles() {
}
public PacketPlayOutWorldParticles(String s, float f, float f1, float f2, float f3, float f4, float f5, float f6, int i, boolean displayFar) {
this.a = s;
this.b = f;
this.c = f1;
this.d = f2;
this.e = f3;
this.f = f4;
this.g = f5;
this.h = f6;
this.i = i;
_displayFar = displayFar;
}
public void a(PacketDataSerializer packetdataserializer) throws IOException {
this.a = packetdataserializer.c(64);
this.b = packetdataserializer.readFloat();
this.c = packetdataserializer.readFloat();
this.d = packetdataserializer.readFloat();
this.e = packetdataserializer.readFloat();
this.f = packetdataserializer.readFloat();
this.g = packetdataserializer.readFloat();
this.h = packetdataserializer.readFloat();
this.i = packetdataserializer.readInt();
}
public void b(PacketDataSerializer packetdataserializer) throws IOException {
String[] parts = this.a.split("_");
PacketPlayOutWorldParticles.Particle particle = PacketPlayOutWorldParticles.Particle.find(parts[0]);
if(particle == null) {
particle = PacketPlayOutWorldParticles.Particle.CRIT;
}
if(packetdataserializer.version < 17) {
packetdataserializer.a(this.a);
} else {
packetdataserializer.writeInt(particle.ordinal());
packetdataserializer.writeBoolean(_displayFar);
}
packetdataserializer.writeFloat(this.b);
packetdataserializer.writeFloat(this.c);
packetdataserializer.writeFloat(this.d);
packetdataserializer.writeFloat(this.e);
packetdataserializer.writeFloat(this.f);
packetdataserializer.writeFloat(this.g);
packetdataserializer.writeFloat(this.h);
packetdataserializer.writeInt(this.i);
if(packetdataserializer.version >= 17) {
for(int i = 0; i < particle.extra; ++i) {
int toWrite = 0;
if(parts.length - 1 > i) {
try {
toWrite = Integer.parseInt(parts[i + 1]);
if(particle.extra == 1 && parts.length == 3) {
++i;
toWrite |= Integer.parseInt(parts[i + 1]) << 12;
}
} catch (NumberFormatException var7) {
;
}
}
packetdataserializer.b(toWrite);
}
}
}
public void a(PacketPlayOutListener packetplayoutlistener) {
packetplayoutlistener.a(this);
}
public void handle(PacketListener packetlistener) {
this.a((PacketPlayOutListener)packetlistener);
}
private static enum Particle {
EXPLOSION_NORMAL("explode"),
EXPLOSION_LARGE("largeexplode"),
EXPLOSION_HUGE("hugeexplosion"),
FIREWORKS_SPARK("fireworksSpark"),
WATER_BUBBLE("bubble"),
WATER_SPLASH("splash"),
WATER_WAKE("wake"),
SUSPENDED("suspended"),
SUSPENDED_DEPTH("depthsuspend"),
CRIT("crit"),
CRIT_MAGIC("magicCrit"),
SMOKE_NORMAL("smoke"),
SMOKE_LARGE("largesmoke"),
SPELL("spell"),
SPELL_INSTANT("instantSpell"),
SPELL_MOB("mobSpell"),
SPELL_MOB_AMBIENT("mobSpellAmbient"),
SPELL_WITCH("witchMagic"),
DRIP_WATER("dripWater"),
DRIP_LAVA("dripLava"),
VILLAGER_ANGRY("angryVillager"),
VILLAGER_HAPPY("happyVillager"),
TOWN_AURA("townaura"),
NOTE("note"),
PORTAL("portal"),
ENCHANTMENT_TABLE("enchantmenttable"),
FLAME("flame"),
LAVA("lava"),
FOOTSTEP("footstep"),
CLOUD("cloud"),
REDSTONE("reddust"),
SNOWBALL("snowballpoof"),
SNOW_SHOVEL("snowshovel"),
SLIME("slime"),
HEART("heart"),
BARRIER("barrier"),
ICON_CRACK("iconcrack", 2),
BLOCK_CRACK("blockcrack", 1),
BLOCK_DUST("blockdust", 1),
WATER_DROP("droplet"),
ITEM_TAKE("take"),
MOB_APPEARANCE("mobappearance");
public final String name;
public final int extra;
private static final HashMap<String, PacketPlayOutWorldParticles.Particle> particleMap;
private Particle(String name) {
this(name, 0);
}
private Particle(String name, int extra) {
this.name = name;
this.extra = extra;
}
public static PacketPlayOutWorldParticles.Particle find(String part) {
return (PacketPlayOutWorldParticles.Particle)particleMap.get(part);
}
static {
particleMap = new HashMap();
PacketPlayOutWorldParticles.Particle[] var0 = values();
int var1 = var0.length;
for(int var2 = 0; var2 < var1; ++var2) {
PacketPlayOutWorldParticles.Particle particle = var0[var2];
particleMap.put(particle.name, particle);
}
}
}
}

View File

@ -179,54 +179,10 @@ public class UtilParticle
}
private static PacketPlayOutWorldParticles getPacket(String particleName, Location location, float offsetX, float offsetY,
float offsetZ, float speed, int count)
float offsetZ, float speed, int count, boolean displayFar)
{
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles();
for (Field field : packet.getClass().getDeclaredFields())
{
try
{
field.setAccessible(true);
String fieldName = field.getName();
switch (fieldName)
{
case "a":
field.set(packet, particleName); // Particle name
break;
case "b":
field.setFloat(packet, (float) location.getX()); // Block X
break;
case "c":
field.setFloat(packet, (float) location.getY()); // Block Y
break;
case "d":
field.setFloat(packet, (float) location.getZ()); // Block Z
break;
case "e":
field.setFloat(packet, offsetX); // Random X Offset
break;
case "f":
field.setFloat(packet, offsetY); // Random Y Offset
break;
case "g":
field.setFloat(packet, offsetZ); // Random Z Offset
break;
case "h":
field.setFloat(packet, speed); // Speed/data of particles
break;
case "i":
field.setInt(packet, count); // Amount of particles
break;
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particleName, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, displayFar);
return packet;
}
@ -242,10 +198,22 @@ public class UtilParticle
PlayParticle(player, type.particleName, location, offsetX, offsetY, offsetZ, speed, count);
}
public static void PlayParticle(Player player, String particleName, Location location, float offsetX, float offsetY,
float offsetZ, float speed, int count)
public static void PlayParticle(Player player, ParticleType type, Location location, float offsetX, float offsetY,
float offsetZ, float speed, int count, boolean displayFar)
{
PacketPlayOutWorldParticles packet = getPacket(particleName, location, offsetX, offsetY, offsetZ, speed, count);
PlayParticle(player, type.particleName, location, offsetX, offsetY, offsetZ, speed, count, displayFar);
}
public static void PlayParticle(Player player, String particleName, Location location, float offsetX, float offsetY,
float offsetZ, float speed, int count)
{
PlayParticle(player, particleName, location, offsetX, offsetY, offsetZ, speed, count, false);
}
public static void PlayParticle(Player player, String particleName, Location location, float offsetX, float offsetY,
float offsetZ, float speed, int count, boolean displayFar)
{
PacketPlayOutWorldParticles packet = getPacket(particleName, location, offsetX, offsetY, offsetZ, speed, count, false);
UtilPlayer.sendPacket(player, packet);
}
@ -253,7 +221,7 @@ public class UtilParticle
public static void PlayParticle(String particleName, Location location, float offsetX, float offsetY, float offsetZ,
float speed, int count)
{
PacketPlayOutWorldParticles packet = getPacket(particleName, location, offsetX, offsetY, offsetZ, speed, count);
PacketPlayOutWorldParticles packet = getPacket(particleName, location, offsetX, offsetY, offsetZ, speed, count, true);
for (Player player : UtilServer.getPlayers())
{

View File

@ -78,6 +78,7 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerPrepareTeleportEvent;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.build.gui.MobShop;
import nautilus.game.arcade.game.games.build.gui.OptionsShop;
import nautilus.game.arcade.game.games.draw.kits.*;
import nautilus.game.arcade.kit.Kit;
@ -97,7 +98,8 @@ public class Build extends SoloGame
private String _word = "?";
private OptionsShop _shop;
private OptionsShop _optionsShop;
private MobShop _mobShop;
private ItemStack _shopItem;
public Build(ArcadeManager manager)
@ -140,7 +142,8 @@ public class Build extends SoloGame
"Pirate Ship", "Mineshaft", "Archers Tower", "Dinner Table", "Pokemon"
};
_shop = new OptionsShop(this, getArcadeManager(), getArcadeManager().GetClients(), getArcadeManager().GetDonation());
_mobShop = new MobShop(getArcadeManager(), getArcadeManager().GetClients(), getArcadeManager().GetDonation());
_optionsShop = new OptionsShop(this, getArcadeManager(), getArcadeManager().GetClients(), getArcadeManager().GetDonation());
_shopItem = ItemStackFactory.Instance.CreateStack(Material.DIAMOND, (byte) 0, 1, C.cGreen + "Options");
}
@ -936,7 +939,7 @@ public class Build extends SoloGame
public void openShop(PlayerInteractEvent event)
{
if (IsAlive(event.getPlayer()) && _shopItem.equals(event.getPlayer().getItemInHand()))
_shop.attemptShopOpen(event.getPlayer());
_optionsShop.attemptShopOpen(event.getPlayer());
}
@EventHandler
@ -1087,4 +1090,25 @@ public class Build extends SoloGame
{
event.blockList().clear();
}
@EventHandler
public void openMobGui(PlayerInteractEntityEvent event)
{
if (!IsLive() || !IsAlive(event.getPlayer())) return;
Player player = event.getPlayer();
BuildData buildData = _data.get(player);
if (buildData != null)
{
for (Entity e : buildData.Entities)
{
if (e.equals(event.getRightClicked()))
{
_mobShop.attemptShopOpen(player, buildData, e);
return;
}
}
}
}
}

View File

@ -0,0 +1,54 @@
package nautilus.game.arcade.game.games.build.gui;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.build.BuildData;
import nautilus.game.arcade.game.games.build.gui.page.MobPage;
public class MobShop extends ShopBase<ArcadeManager>
{
public MobShop(ArcadeManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super(plugin, clientManager, donationManager, "Mob Options");
}
protected ShopPageBase<ArcadeManager, ? extends ShopBase<ArcadeManager>> buildPagesFor(Player player, BuildData data, Entity entity)
{
return new MobPage(getPlugin(), this, getClientManager(), getDonationManager(), player, data, entity);
}
public boolean attemptShopOpen(Player player, BuildData data, Entity entity)
{
if (!getOpenedShop().contains(player.getName()))
{
if (!canOpenShop(player))
return false;
getOpenedShop().add(player.getName());
openShopForPlayer(player);
if (!getPlayerPageMap().containsKey(player.getName()))
{
getPlayerPageMap().put(player.getName(), buildPagesFor(player, data, entity));
}
openPageForPlayer(player, getOpeningPageForPlayer(player));
return true;
}
return false;
}
@Override
protected ShopPageBase<ArcadeManager, ? extends ShopBase<ArcadeManager>> buildPagesFor(Player player)
{
return null;
}
}

View File

@ -8,7 +8,7 @@ import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.build.gui.page.OptionsMenu;
import nautilus.game.arcade.game.games.build.gui.page.OptionsPage;
public class OptionsShop extends ShopBase<ArcadeManager>
{
@ -23,6 +23,6 @@ public class OptionsShop extends ShopBase<ArcadeManager>
@Override
protected ShopPageBase<ArcadeManager, ? extends ShopBase<ArcadeManager>> buildPagesFor(Player player)
{
return new OptionsMenu(_game, getPlugin(), this, getClientManager(), getDonationManager(), player);
return new OptionsPage(_game, getPlugin(), this, getClientManager(), getDonationManager(), player);
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.game.games.build.gui.page;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.build.BuildData;
import nautilus.game.arcade.game.games.build.gui.MobShop;
public class MobPage extends ShopPageBase<ArcadeManager, MobShop>
{
private BuildData _buildData;
private Entity _entity;
public MobPage(ArcadeManager plugin, MobShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, BuildData buildData, Entity entity)
{
super(plugin, shop, clientManager, donationManager, "Mob Options", player);
_buildData = buildData;
_entity = entity;
}
@Override
protected void buildPage()
{
}
}

View File

@ -13,11 +13,11 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.build.gui.OptionsShop;
public class OptionsMenu extends ShopPageBase<ArcadeManager, OptionsShop>
public class OptionsPage extends ShopPageBase<ArcadeManager, OptionsShop>
{
private Build _game;
public OptionsMenu(Build game, ArcadeManager plugin, OptionsShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
public OptionsPage(Build game, ArcadeManager plugin, OptionsShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Options", player, 9);
_game = game;

View File

@ -79,7 +79,7 @@ public class ParticlesPage extends ShopPageBase<ArcadeManager, OptionsShop>
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(player, new OptionsMenu(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
getShop().openPageForPlayer(player, new OptionsPage(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
});
}

View File

@ -62,7 +62,7 @@ public class TimePage extends ShopPageBase<ArcadeManager, OptionsShop>
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(player, new OptionsMenu(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
getShop().openPageForPlayer(player, new OptionsPage(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
});
}

View File

@ -93,7 +93,7 @@ public class WeatherPage extends ShopPageBase<ArcadeManager, OptionsShop>
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(player, new OptionsMenu(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
getShop().openPageForPlayer(player, new OptionsPage(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
});
}