use of net.minecraft.server.v1_12_R1.PlayerInventory in project VehiclesPlus2.0 by legofreak107.
the class Car method Car.
public static void Car(PacketPlayInSteerVehicle ppisv, Player p) {
ArmorStand a2 = (ArmorStand) p.getVehicle();
Seat s = plugin.seatInfo.get(a2);
ArmorStand a = (ArmorStand) s.parent;
Vehicle v = plugin.vehicleInfo.get(a);
if (v.running) {
if (v.curSpeed > 0)
v.mileAge += 0.005 * v.curSpeed;
if (v.curSpeed < 0)
v.mileAge -= 0.005 * v.curSpeed;
if (p.getOpenInventory() != null && p.getOpenInventory() instanceof PlayerInventory) {
p.openInventory(v.inv);
}
float forward = ppisv.b();
float side = ppisv.a();
if (v.fuelbar == null) {
BossBar b = Bukkit.createBossBar("fuel" + v.owner, BarColor.GREEN, BarStyle.SOLID);
v.fuelbar = b;
}
Location tloc = a2.getLocation().clone();
Location smoke = tloc.add(tloc.getDirection().setY(0).normalize().multiply(-1.5));
smoke.getWorld().spawnParticle(Particle.SMOKE_LARGE, smoke.getX(), smoke.getY() + 1, smoke.getZ(), 1, 0, 0, 0, 0);
v.fuelbar.setTitle("�2Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
v.fuelbar.setProgress((v.fuel / v.maxFuel));
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("�6Mileage: " + (int) v.mileAge).create());
if (!v.parts.ENGINE) {
} else {
if (v.fuelbar.getPlayers().contains(p)) {
} else {
v.fuelbar.addPlayer(p);
v.fuelbar.setVisible(true);
}
if (v.fuel <= 0.5) {
v.fuelbar.setTitle("Out of fuel!");
v.running = false;
} else {
v.fuel -= v.fualUsage / 2;
if (forward > 0) {
// Forward[W]
int broken = randInt(0, (int) (20000));
int brokenEngine = randInt(0, (int) (5000000 / (v.mileAge + 1)));
int oil = randInt(0, 100);
if (brokenEngine == 0) {
v.parts.ENGINE = false;
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 10);
p.sendMessage("�2It looks like you have blown up your engine...");
} else if (broken == 1) {
v.parts.WHEELFL = false;
p.sendMessage("�2It looks like your front left tire is flat.");
} else if (broken == 2) {
v.parts.WHEELFR = false;
p.sendMessage("�2It looks like your front right tire is flat.");
} else if (broken == 3) {
v.parts.WHEELRL = false;
p.sendMessage("�2It looks like your rear left tire is flat.");
} else if (broken == 4) {
v.parts.WHEELRR = false;
p.sendMessage("�2It looks like your rear right tire is flat.");
}
v.fuel -= v.fualUsage / 2;
if (v.curSpeed <= v.fspeed || v.curSpeed == 0) {
v.curSpeed = v.curSpeed += v.acceleration / 2;
}
if (!v.parts.WHEELFL || !v.parts.WHEELFR || !v.parts.WHEELRL || !v.parts.WHEELRR) {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed / 4));
} else {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
if (side > 0) {
// Side[A]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
v.steering = (int) (v.turnSpeed / 2);
} else if (side < 0) {
// Side[D]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
v.steering = -(int) (v.turnSpeed / 2);
} else {
v.steering = 0;
}
} else if (forward < 0) {
// Reverse[S]
v.fuel -= v.fualUsage / 2;
Location loc1 = new Location(a.getWorld(), a.getLocation().getBlockX() + 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
Location loc2 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
Location loc3 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() + 1);
Location loc4 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() - 1);
Location loc5 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
if (v.curSpeed >= -v.bspeed || v.curSpeed == 0) {
v.curSpeed = v.curSpeed -= v.acceleration * 2;
}
if ((loc1.getBlock().getType() != Material.AIR && loc1.getBlock().getType() != Material.LONG_GRASS && loc1.getBlock().getType() != Material.CHORUS_FLOWER && loc1.getBlock().getType() != Material.YELLOW_FLOWER && loc1.getBlock().getType() != Material.RED_ROSE && loc1.getBlock().getType() != Material.WHEAT) || (loc2.getBlock().getType() != Material.AIR && loc2.getBlock().getType() != Material.LONG_GRASS && loc2.getBlock().getType() != Material.CHORUS_FLOWER && loc2.getBlock().getType() != Material.YELLOW_FLOWER && loc2.getBlock().getType() != Material.RED_ROSE && loc2.getBlock().getType() != Material.WHEAT) || (loc3.getBlock().getType() != Material.AIR && loc3.getBlock().getType() != Material.LONG_GRASS && loc3.getBlock().getType() != Material.CHORUS_FLOWER && loc3.getBlock().getType() != Material.YELLOW_FLOWER && loc3.getBlock().getType() != Material.RED_ROSE && loc3.getBlock().getType() != Material.WHEAT) || (loc4.getBlock().getType() != Material.AIR && loc4.getBlock().getType() != Material.LONG_GRASS && loc4.getBlock().getType() != Material.CHORUS_FLOWER && loc4.getBlock().getType() != Material.YELLOW_FLOWER && loc4.getBlock().getType() != Material.RED_ROSE && loc4.getBlock().getType() != Material.WHEAT) && loc5.getBlock().getType() != Material.AIR) {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
// a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(- BwdDriveSpeed.get(a.getUniqueId())));
} else {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
if (side > 0) {
// Side[A]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
v.steering = (int) (v.turnSpeed / 2);
} else if (side < 0) {
// Side[D]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
v.steering = -(int) (v.turnSpeed / 2);
} else {
v.steering = 0;
}
} else {
v.steering = 0;
if (v.curSpeed > v.acceleration) {
v.curSpeed = v.curSpeed -= v.acceleration;
} else if (v.curSpeed < -v.acceleration) {
v.curSpeed = v.curSpeed += v.acceleration;
} else {
v.curSpeed = 0;
}
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
}
}
}
}
use of net.minecraft.server.v1_12_R1.PlayerInventory in project PublicCrafters by BananaPuncher714.
the class CustomContainerEnchantTable method b.
@Override
public void b(EntityHuman entity) {
PlayerInventory playerinventory = entity.inventory;
if (!playerinventory.getCarried().isEmpty()) {
entity.drop(playerinventory.getCarried(), false);
playerinventory.setCarried(ItemStack.a);
}
}
use of net.minecraft.server.v1_12_R1.PlayerInventory in project PublicCrafters by BananaPuncher714.
the class CustomTileEntityContainerEnchantTable method createContainer.
@Override
public Container createContainer(PlayerInventory paramPlayerInventory, EntityHuman ent) {
IInventory crafting = manager.tables.get(bloc);
CustomContainerEnchantTable container = new CustomContainerEnchantTable(ent.getBukkitEntity(), bloc, crafting);
if (crafting == null) {
manager.tables.put(bloc, container.enchantSlots);
}
return container;
}
use of net.minecraft.server.v1_12_R1.PlayerInventory in project PublicCrafters by BananaPuncher714.
the class CustomTileEntityContainerWorkbench method createContainer.
/**
* This is an ITileEntityContainer method that returns a new container for whatever tile entity
*/
@Override
public Container createContainer(PlayerInventory paramPlayerInventory, EntityHuman ent) {
CustomInventoryCrafting crafting = manager.benches.get(bloc);
if (crafting == null) {
crafting = new CustomInventoryCrafting(bloc, manager, new SelfContainer(), 3, 3);
manager.put(bloc, crafting);
}
IInventory inventory = crafting.resultInventory;
InventoryCraftResult result;
if (inventory instanceof InventoryCraftResult || inventory == null) {
result = new InventoryCraftResult();
crafting.resultInventory = result;
} else {
result = (InventoryCraftResult) inventory;
}
Container container = new CustomContainerWorkbench(ent.getBukkitEntity(), bloc, crafting, result);
crafting.addContainer(container);
return container;
}
use of net.minecraft.server.v1_12_R1.PlayerInventory in project PaperDev by Kamillaova.
the class CraftContainer method setupSlots.
private void setupSlots(IInventory top, PlayerInventory bottom, EntityHuman entityhuman) {
switch(cachedType) {
case CREATIVE:
// TODO: This should be an error?
break;
case PLAYER:
case CHEST:
delegate = new ContainerChest(bottom, top, entityhuman);
break;
case DISPENSER:
case DROPPER:
delegate = new ContainerDispenser(bottom, top);
break;
case FURNACE:
delegate = new ContainerFurnace(bottom, top);
break;
// TODO: This should be an error?
case CRAFTING:
case WORKBENCH:
// SPIGOT-3812 - manually set up slots so we can use the delegated inventory and not the automatically created one
setupWorkbench(top, bottom);
break;
case ENCHANTING:
delegate = new ContainerEnchantTable(bottom, entityhuman.world, entityhuman.getChunkCoordinates());
break;
case BREWING:
delegate = new ContainerBrewingStand(bottom, top);
break;
case HOPPER:
delegate = new ContainerHopper(bottom, top, entityhuman);
break;
case ANVIL:
delegate = new ContainerAnvil(bottom, entityhuman.world, entityhuman.getChunkCoordinates(), entityhuman);
break;
case BEACON:
delegate = new ContainerBeacon(bottom, top);
break;
case SHULKER_BOX:
delegate = new ContainerShulkerBox(bottom, top, entityhuman);
break;
}
if (delegate != null) {
this.items = delegate.items;
this.slots = delegate.slots;
}
}
Aggregations