231 lines
5.9 KiB
Java
231 lines
5.9 KiB
Java
/*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.gmail.filoghost.holographicdisplays.nms.v1_12_R1;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
|
|
import com.gmail.filoghost.holographicdisplays.api.line.HologramLine;
|
|
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSEntityBase;
|
|
import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSSlime;
|
|
import com.gmail.filoghost.holographicdisplays.util.ConsoleLogger;
|
|
import com.gmail.filoghost.holographicdisplays.util.reflection.ReflectField;
|
|
|
|
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
|
import net.minecraft.server.v1_12_R1.DamageSource;
|
|
import net.minecraft.server.v1_12_R1.Entity;
|
|
import net.minecraft.server.v1_12_R1.EntityDamageSource;
|
|
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
|
import net.minecraft.server.v1_12_R1.EntitySlime;
|
|
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
|
import net.minecraft.server.v1_12_R1.SoundEffect;
|
|
import net.minecraft.server.v1_12_R1.World;
|
|
|
|
public class EntityNMSSlime extends EntitySlime implements NMSSlime {
|
|
|
|
private static final ReflectField<Entity> VEHICLE_FIELD = new ReflectField<Entity>(Entity.class, "au");
|
|
|
|
private boolean lockTick;
|
|
private HologramLine parentPiece;
|
|
|
|
public EntityNMSSlime(World world, HologramLine parentPiece) {
|
|
super(world);
|
|
super.persistent = true;
|
|
super.collides = false;
|
|
a(0.0F, 0.0F);
|
|
setSize(1, false);
|
|
setInvisible(true);
|
|
this.parentPiece = parentPiece;
|
|
forceSetBoundingBox(new NullBoundingBox());
|
|
}
|
|
|
|
@Override
|
|
public void a(AxisAlignedBB boundingBox) {
|
|
// Do not change it!
|
|
}
|
|
|
|
public void forceSetBoundingBox(AxisAlignedBB boundingBox) {
|
|
super.a(boundingBox);
|
|
}
|
|
|
|
@Override
|
|
public void B_() {
|
|
|
|
// So it won't get removed.
|
|
ticksLived = 0;
|
|
|
|
if (!lockTick) {
|
|
super.B_();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
// Do not save NBT.
|
|
}
|
|
|
|
@Override
|
|
public boolean c(NBTTagCompound nbttagcompound) {
|
|
// Do not save NBT.
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean d(NBTTagCompound nbttagcompound) {
|
|
// Do not save NBT.
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
|
|
// Do not save NBT.
|
|
return nbttagcompound;
|
|
}
|
|
|
|
@Override
|
|
public void f(NBTTagCompound nbttagcompound) {
|
|
// Do not load NBT.
|
|
}
|
|
|
|
@Override
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
// Do not load NBT.
|
|
}
|
|
|
|
@Override
|
|
public boolean damageEntity(DamageSource damageSource, float amount) {
|
|
if (damageSource instanceof EntityDamageSource) {
|
|
EntityDamageSource entityDamageSource = (EntityDamageSource) damageSource;
|
|
if (entityDamageSource.getEntity() instanceof EntityPlayer) {
|
|
Bukkit.getPluginManager().callEvent(new PlayerInteractEntityEvent(((EntityPlayer) entityDamageSource.getEntity()).getBukkitEntity(), getBukkitEntity())); // Bukkit takes care of the exceptions
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isInvulnerable(DamageSource source) {
|
|
/*
|
|
* The field Entity.invulnerable is private.
|
|
* It's only used while saving NBTTags, but since the entity would be killed
|
|
* on chunk unload, we prefer to override isInvulnerable().
|
|
*/
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isCollidable() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void inactiveTick() {
|
|
// Check inactive ticks.
|
|
|
|
if (!lockTick) {
|
|
super.inactiveTick();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setCustomName(String customName) {
|
|
// Locks the custom name.
|
|
}
|
|
|
|
@Override
|
|
public void setCustomNameVisible(boolean visible) {
|
|
// Locks the custom name.
|
|
}
|
|
|
|
@Override
|
|
public void a(SoundEffect soundeffect, float f, float f1) {
|
|
// Remove sounds.
|
|
}
|
|
|
|
@Override
|
|
public void setLockTick(boolean lock) {
|
|
lockTick = lock;
|
|
}
|
|
|
|
@Override
|
|
public void die() {
|
|
// Prevent being killed.
|
|
}
|
|
|
|
@Override
|
|
public CraftEntity getBukkitEntity() {
|
|
if (super.bukkitEntity == null) {
|
|
super.bukkitEntity = new CraftNMSSlime(super.world.getServer(), this);
|
|
}
|
|
return super.bukkitEntity;
|
|
}
|
|
|
|
@Override
|
|
public boolean isDeadNMS() {
|
|
return super.dead;
|
|
}
|
|
|
|
@Override
|
|
public void killEntityNMS() {
|
|
super.dead = true;
|
|
}
|
|
|
|
@Override
|
|
public void setLocationNMS(double x, double y, double z) {
|
|
super.setPosition(x, y, z);
|
|
}
|
|
|
|
@Override
|
|
public int getIdNMS() {
|
|
return super.getId();
|
|
}
|
|
|
|
@Override
|
|
public HologramLine getHologramLine() {
|
|
return parentPiece;
|
|
}
|
|
|
|
@Override
|
|
public org.bukkit.entity.Entity getBukkitEntityNMS() {
|
|
return getBukkitEntity();
|
|
}
|
|
|
|
@Override
|
|
public void setPassengerOfNMS(NMSEntityBase vehicleBase) {
|
|
if (vehicleBase == null || !(vehicleBase instanceof Entity)) {
|
|
// It should never dismount
|
|
return;
|
|
}
|
|
|
|
Entity entity = (Entity) vehicleBase;
|
|
|
|
try {
|
|
if (super.bJ() != null) {
|
|
Entity oldVehicle = super.bJ();
|
|
VEHICLE_FIELD.set(this, null);
|
|
oldVehicle.passengers.remove(this);
|
|
}
|
|
|
|
VEHICLE_FIELD.set(this, entity);
|
|
entity.passengers.clear();
|
|
entity.passengers.add(this);
|
|
|
|
} catch (Exception ex) {
|
|
ConsoleLogger.logDebugException(ex);
|
|
}
|
|
}
|
|
}
|