From 4b1b45038f387e80cc16420d0b40a23a06b0f4c4 Mon Sep 17 00:00:00 2001 From: makeo Date: Sun, 5 Jun 2016 16:04:19 +0200 Subject: [PATCH] Sending keep alive to GitHub-repo. Added example src for disabling mob collision --- .../common/blocks/tiles/TileAISuppressor.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/makeo/gadomancy/common/blocks/tiles/TileAISuppressor.java diff --git a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileAISuppressor.java b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileAISuppressor.java new file mode 100644 index 0000000..ddbf935 --- /dev/null +++ b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileAISuppressor.java @@ -0,0 +1,49 @@ +package makeo.gadomancy.common.blocks.tiles; + +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class is part of the Gadomancy Mod + * Gadomancy is Open Source and distributed under the + * GNU LESSER GENERAL PUBLIC LICENSE + * for more read the LICENSE file + *

+ * Created by makeo @ 05.06.2016 15:35 + */ +public class TileAISuppressor extends SynchronizedTileEntity { + private static final AxisAlignedBB PART_RANGE = AxisAlignedBB.getBoundingBox(0, 0, 0, 10, 10, 10); + + private Map tracked = new HashMap(); + private int count = 0; + + @Override + public void updateEntity() { + if(count++ % 10 == 0) { + AxisAlignedBB cube = PART_RANGE.addCoord(xCoord + .5 - ((PART_RANGE.maxX - PART_RANGE.minX) / 2), yCoord + .5 - ((PART_RANGE.maxY - PART_RANGE.minY) / 2), zCoord + .5 - ((PART_RANGE.maxZ - PART_RANGE.minZ) / 2)); + List entities = worldObj.getEntitiesWithinAABB(Entity.class, cube); + + List outdated = new ArrayList(tracked.keySet()); + + for(Entity entity : entities) { + if(!tracked.containsKey(entity)) { + tracked.put(entity, entity.entityCollisionReduction); + } + + entity.entityCollisionReduction = 0; + outdated.remove(entity); + } + + for(Entity entity : outdated) { + float val = tracked.get(entity); + tracked.remove(entity); + entity.entityCollisionReduction = val; + } + } + } +}