From 5856a6623641697349a112ff75b74296358361a0 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Wed, 24 Oct 2018 02:38:23 +0100 Subject: + Added Base framework for custom GC systems. % Tweaked Automatic doors, they will not open if mobs are within 2m or if open, they will close. --- .../general/TileEntityPlayerDoorBase.java | 82 +++++++++++++++++++--- 1 file changed, 71 insertions(+), 11 deletions(-) (limited to 'src/Java/gtPlusPlus/core/tileentities') diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java index 7df4bd45f3..48f05fe0fd 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java @@ -1,12 +1,19 @@ package gtPlusPlus.core.tileentities.general; +import java.util.ArrayList; +import java.util.List; + +import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.minecraft.EntityUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockDoor; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; public class TileEntityPlayerDoorBase extends TileEntity { @@ -69,6 +76,8 @@ public class TileEntityPlayerDoorBase extends TileEntity { return 0; } + AutoMap mNearbyEntityCache = new AutoMap(); + @Override public void updateEntity() { @@ -125,43 +134,94 @@ public class TileEntityPlayerDoorBase extends TileEntity { } } - if (mTickCounter % 4 == 0) { - int aDoorState = 0; + World aWorld = this.getWorldObj(); + Block aBlock = aWorld.getBlock(xCoord, yCoord, zCoord); + BlockPos aThisPos = new BlockPos(xCoord, yCoord, zCoord, this.worldObj); + + if (mTickCounter % 20 == 0) { + int x = 0, y = 0, z = 0; + x = this.xCoord; + y = this.yCoord; + z = this.zCoord; + //List aEntityList = aWorld.loadedEntityList; + List aEntityList = new ArrayList(); + Chunk aThisChunk = aWorld.getChunkFromBlockCoords(x, z); + for (List l : aThisChunk.entityLists) { + aEntityList.addAll(l); + } + for (Object o : aEntityList) { + if (o != null) { + if (o instanceof Entity) { + if (o instanceof EntityPlayer) { + continue; + } + else { + Entity e = (Entity) o; + BlockPos p = EntityUtils.findBlockPosUnderEntity(e); + if (p != null) { + int newY = p.yPos+1; + if (e.getDistance(xCoord, yCoord, zCoord) <= 2){ + mNearbyEntityCache.put(e); + } + else if (aThisPos.distanceFrom(p.xPos, newY, p.zPos) <= 2) { + mNearbyEntityCache.put(e); + } + } + } + } + } + } + } + + if (mTickCounter % 4 == 0) { + for (Entity y : mNearbyEntityCache) { + if (y.getDistance(xCoord, yCoord, zCoord) > 2){ + mNearbyEntityCache.remove(y); + } + } + + boolean foundMonster = mNearbyEntityCache.size() > 0; + int aNeighbourDoorState = 0; if (mNeighbourDoor != null) { - aDoorState = getNeighbourState(); + aNeighbourDoorState = getNeighbourState(); } - World aWorld = this.getWorldObj(); - Block aBlock = aWorld.getBlock(xCoord, yCoord, zCoord); BlockDoor aDoor = (aBlock instanceof BlockDoor ? (BlockDoor) aBlock : null); boolean aPlayers = checkForPlayers(this.getWorldObj()); if (aDoor != null) { - if (aDoorState != 0 && mMeta == -1) { - if (aDoorState == 100) { - if (!mIsOpen) { + //If neighbour state != 0 and we are in slave mode + if (aNeighbourDoorState != 0 && mMeta == -1) { + if (aNeighbourDoorState == 100) { + if (!mIsOpen && !foundMonster) { //Logger.INFO("Opening Door (Slave)"); aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, true); mIsOpen = true; } - } else if (aDoorState == -100) { + } else if (aNeighbourDoorState == -100 || foundMonster) { if (mIsOpen) { //Logger.INFO("Closing Door (Slave)"); aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, false); mIsOpen = false; } } + //We are master, proceed } else { + //No redstone found, allow automatic handling if (aDoor != null && !hasRedstone()) { + //Found a nearby player if (aPlayers) { - if (!mIsOpen) { + //If we are closed and there are no monsters nearby, open + if (!mIsOpen && !foundMonster) { //Logger.INFO("Opening Door (Mstr)"); aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, true); mIsOpen = true; } else { // Logger.INFO("Doing Nothing, Door is in correct state."); } + //Did not find nearby player } else { - if (mIsOpen) { + //If we are open or there is a monster nearby, close. + if (mIsOpen || foundMonster) { //Logger.INFO("Closing Door (Mstr)"); aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, false); mIsOpen = false; -- cgit