#1367: Add more Conduit API
This commit is contained in:
parent
1a1bda9b9a
commit
1703691225
@ -1,6 +1,42 @@
|
|||||||
--- a/net/minecraft/world/level/block/entity/TileEntityConduit.java
|
--- a/net/minecraft/world/level/block/entity/TileEntityConduit.java
|
||||||
+++ b/net/minecraft/world/level/block/entity/TileEntityConduit.java
|
+++ b/net/minecraft/world/level/block/entity/TileEntityConduit.java
|
||||||
@@ -201,7 +201,7 @@
|
@@ -40,11 +40,11 @@
|
||||||
|
private float activeRotation;
|
||||||
|
private boolean isActive;
|
||||||
|
private boolean isHunting;
|
||||||
|
- private final List<BlockPosition> effectBlocks = Lists.newArrayList();
|
||||||
|
+ public final List<BlockPosition> effectBlocks = Lists.newArrayList();
|
||||||
|
@Nullable
|
||||||
|
- private EntityLiving destroyTarget;
|
||||||
|
+ public EntityLiving destroyTarget;
|
||||||
|
@Nullable
|
||||||
|
- private UUID destroyTargetUUID;
|
||||||
|
+ public UUID destroyTargetUUID;
|
||||||
|
private long nextAmbientSoundActivation;
|
||||||
|
|
||||||
|
public TileEntityConduit(BlockPosition blockposition, IBlockData iblockdata) {
|
||||||
|
@@ -186,8 +186,20 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyEffects(World world, BlockPosition blockposition, List<BlockPosition> list) {
|
||||||
|
+ // CraftBukkit start
|
||||||
|
+ applyEffects(world, blockposition, getRange(list));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public static int getRange(List<BlockPosition> list) {
|
||||||
|
+ // CraftBukkit end
|
||||||
|
int i = list.size();
|
||||||
|
int j = i / 7 * 16;
|
||||||
|
+ // CraftBukkit start
|
||||||
|
+ return j;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ private static void applyEffects(World world, BlockPosition blockposition, int j) { // j = effect range in blocks
|
||||||
|
+ // CraftBukkit end
|
||||||
|
int k = blockposition.getX();
|
||||||
|
int l = blockposition.getY();
|
||||||
|
int i1 = blockposition.getZ();
|
||||||
|
@@ -201,7 +213,7 @@
|
||||||
EntityHuman entityhuman = (EntityHuman) iterator.next();
|
EntityHuman entityhuman = (EntityHuman) iterator.next();
|
||||||
|
|
||||||
if (blockposition.closerThan(entityhuman.blockPosition(), (double) j) && entityhuman.isInWaterOrRain()) {
|
if (blockposition.closerThan(entityhuman.blockPosition(), (double) j) && entityhuman.isInWaterOrRain()) {
|
||||||
@ -9,17 +45,41 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,8 +230,11 @@
|
@@ -209,6 +221,12 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateDestroyTarget(World world, BlockPosition blockposition, IBlockData iblockdata, List<BlockPosition> list, TileEntityConduit tileentityconduit) {
|
||||||
|
+ // CraftBukkit start - add "damageTarget" boolean
|
||||||
|
+ updateDestroyTarget(world, blockposition, iblockdata, list, tileentityconduit, true);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public static void updateDestroyTarget(World world, BlockPosition blockposition, IBlockData iblockdata, List<BlockPosition> list, TileEntityConduit tileentityconduit, boolean damageTarget) {
|
||||||
|
+ // CraftBukkit end
|
||||||
|
EntityLiving entityliving = tileentityconduit.destroyTarget;
|
||||||
|
int i = list.size();
|
||||||
|
|
||||||
|
@@ -229,9 +247,12 @@
|
||||||
|
tileentityconduit.destroyTarget = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tileentityconduit.destroyTarget != null) {
|
- if (tileentityconduit.destroyTarget != null) {
|
||||||
- world.playSound((EntityHuman) null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
- world.playSound((EntityHuman) null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||||
- tileentityconduit.destroyTarget.hurt(world.damageSources().magic(), 4.0F);
|
- tileentityconduit.destroyTarget.hurt(world.damageSources().magic(), 4.0F);
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (tileentityconduit.destroyTarget.hurt(world.damageSources().magic().directBlock(world, blockposition), 4.0F)) { // CraftBukkit
|
+ if (damageTarget && tileentityconduit.destroyTarget != null) {
|
||||||
|
+ if (tileentityconduit.destroyTarget.hurt(world.damageSources().magic().directBlock(world, blockposition), 4.0F)) {
|
||||||
+ world.playSound(null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
+ world.playSound(null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityliving != tileentityconduit.destroyTarget) {
|
if (entityliving != tileentityconduit.destroyTarget) {
|
||||||
|
@@ -252,7 +273,7 @@
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- private static AxisAlignedBB getDestroyRangeAABB(BlockPosition blockposition) {
|
||||||
|
+ public static AxisAlignedBB getDestroyRangeAABB(BlockPosition blockposition) {
|
||||||
|
int i = blockposition.getX();
|
||||||
|
int j = blockposition.getY();
|
||||||
|
int k = blockposition.getZ();
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
package org.bukkit.craftbukkit.block;
|
package org.bukkit.craftbukkit.block;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import net.minecraft.core.BlockPosition;
|
||||||
|
import net.minecraft.world.entity.EntityLiving;
|
||||||
import net.minecraft.world.level.block.entity.TileEntityConduit;
|
import net.minecraft.world.level.block.entity.TileEntityConduit;
|
||||||
|
import net.minecraft.world.phys.AxisAlignedBB;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Conduit;
|
import org.bukkit.block.Conduit;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.util.BoundingBox;
|
||||||
|
|
||||||
public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> implements Conduit {
|
public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> implements Conduit {
|
||||||
|
|
||||||
@ -18,4 +27,99 @@ public class CraftConduit extends CraftBlockEntityState<TileEntityConduit> imple
|
|||||||
public CraftConduit copy() {
|
public CraftConduit copy() {
|
||||||
return new CraftConduit(this);
|
return new CraftConduit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
ensureNoWorldGeneration();
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
return conduit != null && conduit.isActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHunting() {
|
||||||
|
ensureNoWorldGeneration();
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
return conduit != null && conduit.isHunting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Block> getFrameBlocks() {
|
||||||
|
ensureNoWorldGeneration();
|
||||||
|
Collection<Block> blocks = new ArrayList<>();
|
||||||
|
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
if (conduit != null) {
|
||||||
|
for (BlockPosition position : conduit.effectBlocks) {
|
||||||
|
blocks.add(CraftBlock.at(getWorldHandle(), position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFrameBlockCount() {
|
||||||
|
ensureNoWorldGeneration();
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
return (conduit != null) ? conduit.effectBlocks.size() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRange() {
|
||||||
|
ensureNoWorldGeneration();
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
return (conduit != null) ? TileEntityConduit.getRange(conduit.effectBlocks) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setTarget(LivingEntity target) {
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
if (conduit == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityLiving currentTarget = conduit.destroyTarget;
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
if (currentTarget == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
conduit.destroyTarget = null;
|
||||||
|
conduit.destroyTargetUUID = null;
|
||||||
|
} else {
|
||||||
|
if (currentTarget != null && target.getUniqueId().equals(currentTarget.getUUID())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
conduit.destroyTarget = ((CraftLivingEntity) target).getHandle();
|
||||||
|
conduit.destroyTargetUUID = target.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEntityConduit.updateDestroyTarget(conduit.getLevel(), getPosition(), data, conduit.effectBlocks, conduit, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LivingEntity getTarget() {
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
if (conduit == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityLiving nmsEntity = conduit.destroyTarget;
|
||||||
|
return (nmsEntity != null) ? (LivingEntity) nmsEntity.getBukkitEntity() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasTarget() {
|
||||||
|
TileEntityConduit conduit = (TileEntityConduit) getTileEntityFromWorld();
|
||||||
|
return conduit != null && conduit.destroyTarget != null && conduit.destroyTarget.isAlive();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BoundingBox getHuntingArea() {
|
||||||
|
AxisAlignedBB bounds = TileEntityConduit.getDestroyRangeAABB(getPosition());
|
||||||
|
return new BoundingBox(bounds.minX, bounds.minY, bounds.minZ, bounds.maxX, bounds.maxY, bounds.maxZ);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user