use of org.spongepowered.common.accessor.world.entity.decoration.ItemFrameAccessor in project SpongeCommon by SpongePowered.
the class EntityTickPhaseState method postBlockTransactionApplication.
@Override
public void postBlockTransactionApplication(final EntityTickContext context, final BlockChange blockChange, final BlockTransactionReceipt transaction) {
if (blockChange == BlockChange.BREAK) {
final Entity tickingEntity = context.getSource(Entity.class).get();
final BlockPos blockPos = VecHelper.toBlockPos(transaction.originalBlock().position());
final List<HangingEntity> hangingEntities = ((ServerLevel) tickingEntity.world()).getEntitiesOfClass(HangingEntity.class, new AABB(blockPos, blockPos).inflate(1.1D, 1.1D, 1.1D), entityIn -> {
if (entityIn == null) {
return false;
}
final BlockPos entityPos = entityIn.getPos();
// Hanging Neighbor Entity
if (entityPos.equals(blockPos.offset(0, 1, 0))) {
return true;
}
// Check around source block
final Direction entityFacing = entityIn.getDirection();
if (entityFacing == Direction.NORTH) {
return entityPos.equals(blockPos.offset(Constants.Entity.HANGING_OFFSET_NORTH));
} else if (entityFacing == Direction.SOUTH) {
return entityIn.getPos().equals(blockPos.offset(Constants.Entity.HANGING_OFFSET_SOUTH));
} else if (entityFacing == Direction.WEST) {
return entityIn.getPos().equals(blockPos.offset(Constants.Entity.HANGING_OFFSET_WEST));
} else if (entityFacing == Direction.EAST) {
return entityIn.getPos().equals(blockPos.offset(Constants.Entity.HANGING_OFFSET_EAST));
}
return false;
});
for (final HangingEntity entityHanging : hangingEntities) {
if (entityHanging instanceof ItemFrame) {
final ItemFrame itemFrame = (ItemFrame) entityHanging;
if (!itemFrame.removed) {
((ItemFrameAccessor) itemFrame).invoker$dropItem((net.minecraft.world.entity.Entity) tickingEntity, true);
}
itemFrame.remove();
}
}
}
}
Aggregations