mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-22 12:59:48 +00:00
- SUPER AI Shutdown <init>
This commit is contained in:
1 parent
d657306e15
commit
37300f7d0c
14 files changed
+509
-17
No files matched your search
@@ -88,16 +88,14 @@ public class BlockStoneMachine extends Block {
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(int metadata) {
|
||||
return metadata == 15 || metadata == 0 || metadata == 1 || metadata == 2 || metadata == 3 || metadata == 4;
|
||||
return metadata == 15 || metadata == 0 || metadata == 1 || metadata == 2 || metadata == 3 || metadata == 4 || metadata == 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
|
||||
list.add(new ItemStack(item, 1, 0));
|
||||
list.add(new ItemStack(item, 1, 1));
|
||||
list.add(new ItemStack(item, 1, 2));
|
||||
list.add(new ItemStack(item, 1, 3));
|
||||
list.add(new ItemStack(item, 1, 4));
|
||||
for (int i = 0; i < 6; i++) {
|
||||
list.add(new ItemStack(item, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,6 +122,8 @@ public class BlockStoneMachine extends Block {
|
||||
return new TileManipulationFocus();
|
||||
} else if(metadata == 4) {
|
||||
return new TileArcanePackager();
|
||||
} else if(metadata == 5) {
|
||||
return new TileAIShutdown();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -16,6 +17,10 @@ import net.minecraft.tileentity.TileEntity;
|
||||
*/
|
||||
public class SynchronizedTileEntity extends TileEntity {
|
||||
|
||||
public ChunkCoordinates getCoords() {
|
||||
return new ChunkCoordinates(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public final void readFromNBT(NBTTagCompound compound) {
|
||||
super.readFromNBT(compound);
|
||||
readCustomNBT(compound);
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
package makeo.gadomancy.common.blocks.tiles;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import makeo.gadomancy.common.registration.AIShutdownWhitelist;
|
||||
import makeo.gadomancy.common.registration.RegisteredMultiblocks;
|
||||
import makeo.gadomancy.common.utils.Injector;
|
||||
import makeo.gadomancy.common.utils.MultiblockHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.ai.EntityAIBase;
|
||||
import net.minecraft.entity.ai.EntityAITasks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.aspects.IAspectContainer;
|
||||
import thaumcraft.api.aspects.IEssentiaTransport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 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 HellFirePvP @ 08.06.2016 22:56
|
||||
*/
|
||||
public class TileAIShutdown extends SynchronizedTileEntity implements IAspectContainer, IEssentiaTransport {
|
||||
|
||||
private static Map<ChunkCoordinates, List<AffectedEntity>> trackedEntities = Maps.newHashMap();
|
||||
private static AxisAlignedBB BOX = AxisAlignedBB.getBoundingBox(-3, 1, -3, 4, 3, 4);
|
||||
private static Injector injEntityLivingBase = new Injector(EntityLivingBase.class);
|
||||
|
||||
public static final int MAX_AMT = 16;
|
||||
|
||||
private int ticksExisted = 0;
|
||||
private int storedAmount = 0;
|
||||
private boolean foundMultiblock = false;
|
||||
|
||||
@Override
|
||||
public boolean canUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if(worldObj == null) return;
|
||||
ticksExisted++;
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
ChunkCoordinates cc = getCoords();
|
||||
if(!trackedEntities.containsKey(cc)) trackedEntities.put(cc, Lists.<AffectedEntity>newLinkedList());
|
||||
|
||||
if((ticksExisted & 7) == 0) {
|
||||
if(!foundMultiblock) {
|
||||
setMultiblock(checkGrassBlocks());
|
||||
} else {
|
||||
if(!checkGrassBlocks()) {
|
||||
setMultiblock(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMultiblock) return;
|
||||
|
||||
if((ticksExisted & 15) == 0) {
|
||||
killAI();
|
||||
}
|
||||
} else {
|
||||
if(foundMultiblock) {
|
||||
//Effects?
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void killAI() {
|
||||
ChunkCoordinates cc = getCoords();
|
||||
List objEntityList = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, BOX.copy().offset(xCoord, yCoord, zCoord));
|
||||
for (Object o : objEntityList) {
|
||||
if(o != null && o instanceof EntityLiving &&
|
||||
!((EntityLiving) o).isDead && canAffect((EntityLiving) o)) {
|
||||
EntityLiving el = (EntityLiving) o;
|
||||
AffectedEntity affected = removeAI(el);
|
||||
trackedEntities.get(cc).add(affected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AffectedEntity removeAI(EntityLiving el) {
|
||||
UUID uu = el.getUniqueID();
|
||||
List<EntityAITasks.EntityAITaskEntry> tasks =
|
||||
new ArrayList<EntityAITasks.EntityAITaskEntry>(el.tasks.taskEntries);
|
||||
List<EntityAITasks.EntityAITaskEntry> targetTasks =
|
||||
new ArrayList<EntityAITasks.EntityAITaskEntry>(el.targetTasks.taskEntries);
|
||||
|
||||
List<Class<? extends EntityAIBase>> entries = AIShutdownWhitelist.getWhitelistedAIClasses(el);
|
||||
|
||||
Iterator iterator = el.tasks.taskEntries.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Object entry = iterator.next();
|
||||
if (entry == null || !(entry instanceof EntityAITasks.EntityAITaskEntry)) continue;
|
||||
boolean needsRemoval = true;
|
||||
for (Class<? extends EntityAIBase> aiClass : entries) {
|
||||
if(aiClass.isAssignableFrom(((EntityAITasks.EntityAITaskEntry) entry).action.getClass())) needsRemoval = false;
|
||||
}
|
||||
if(needsRemoval) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
iterator = el.targetTasks.taskEntries.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Object entry = iterator.next();
|
||||
if (entry == null || !(entry instanceof EntityAITasks.EntityAITaskEntry)) continue;
|
||||
boolean needsRemoval = true;
|
||||
for (Class<? extends EntityAIBase> aiClass : entries) {
|
||||
if(aiClass.isAssignableFrom(((EntityAITasks.EntityAITaskEntry) entry).action.getClass())) needsRemoval = false;
|
||||
}
|
||||
if(needsRemoval) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
injEntityLivingBase.setObject(el);
|
||||
injEntityLivingBase.setField("ignoreCollisions", true);
|
||||
injEntityLivingBase.setObject(null);
|
||||
return new AffectedEntity(uu, tasks, targetTasks);
|
||||
}
|
||||
|
||||
public void setMultiblock(boolean state) {
|
||||
if(foundMultiblock != state) {
|
||||
this.foundMultiblock = state;
|
||||
markDirty();
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canAffect(EntityLiving el) {
|
||||
ChunkCoordinates cc = getCoords();
|
||||
if(!trackedEntities.containsKey(cc)) return false;
|
||||
UUID uu = el.getUniqueID();
|
||||
for (AffectedEntity ae : trackedEntities.get(cc)) {
|
||||
if(ae.eUUID.equals(uu)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkGrassBlocks() {
|
||||
return MultiblockHelper.isMultiblockPresent(worldObj, xCoord, yCoord, zCoord, RegisteredMultiblocks.aiShutdownPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound compound) {
|
||||
this.storedAmount = compound.getInteger("amount");
|
||||
this.foundMultiblock = compound.getBoolean("multiblock");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomNBT(NBTTagCompound compound) {
|
||||
compound.setInteger("amount", storedAmount);
|
||||
compound.setBoolean("multiblock", foundMultiblock);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// IAspectContainer & IEssentiaTransport
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public AspectList getAspects() {
|
||||
if(storedAmount <= 0) return new AspectList();
|
||||
return new AspectList().add(Aspect.ENTROPY, storedAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAspects(AspectList list) {}
|
||||
|
||||
@Override
|
||||
public boolean doesContainerAccept(Aspect aspect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addToContainer(Aspect aspect, int amount) {
|
||||
if (amount == 0) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
if (aspect == null) return 0;
|
||||
|
||||
if (storedAmount < MAX_AMT) {
|
||||
int added = Math.min(amount, MAX_AMT - storedAmount);
|
||||
storedAmount += added;
|
||||
amount -= added;
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
markDirty();
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takeFromContainer(Aspect aspect, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean takeFromContainer(AspectList list) {
|
||||
return false; //NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesContainerContainAmount(Aspect aspect, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean doesContainerContain(AspectList list) {
|
||||
return false; //NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public int containerContains(Aspect aspect) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectable(ForgeDirection direction) {
|
||||
return direction != null && direction.equals(ForgeDirection.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputFrom(ForgeDirection direction) {
|
||||
return isConnectable(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutputTo(ForgeDirection direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSuction(Aspect aspect, int i) {}
|
||||
|
||||
@Override
|
||||
public Aspect getSuctionType(ForgeDirection direction) {
|
||||
if(!isConnectable(direction)) return null;
|
||||
return Aspect.ENTROPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuctionAmount(ForgeDirection direction) {
|
||||
if(!isConnectable(direction)) return 0;
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int takeEssentia(Aspect aspect, int i, ForgeDirection direction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addEssentia(Aspect aspect, int i, ForgeDirection direction) {
|
||||
return canInputFrom(direction) ? addToContainer(aspect, i) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aspect getEssentiaType(ForgeDirection direction) {
|
||||
if(!isConnectable(direction)) return null;
|
||||
return Aspect.ENTROPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEssentiaAmount(ForgeDirection direction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumSuction() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderExtendedTube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Tracker methods
|
||||
|
||||
public static void removeTrackedEntity(EntityLiving entityLiving) {
|
||||
for (ChunkCoordinates cc : trackedEntities.keySet()) {
|
||||
for (AffectedEntity ae : trackedEntities.get(cc)) {
|
||||
if(ae.eUUID.equals(entityLiving.getUniqueID())) {
|
||||
trackedEntities.get(cc).remove(ae);
|
||||
entityLiving.tasks.taskEntries = ae.tasks;
|
||||
entityLiving.targetTasks.taskEntries = ae.targetTasks;
|
||||
injEntityLivingBase.setObject(entityLiving);
|
||||
injEntityLivingBase.setField("ignoreCollisions", false);
|
||||
injEntityLivingBase.setObject(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeTrackedEntities(World world, int x, int y, int z) {
|
||||
ChunkCoordinates cc = new ChunkCoordinates(x, y, z);
|
||||
if(trackedEntities.containsKey(cc)) {
|
||||
for (AffectedEntity ae : trackedEntities.get(cc)) {
|
||||
for (Object objE : world.getLoadedEntityList()) {
|
||||
if(objE != null && objE instanceof EntityLiving &&
|
||||
!((EntityLiving) objE).isDead &&
|
||||
((EntityLiving) objE).getUniqueID().equals(ae.eUUID)) {
|
||||
((EntityLiving) objE).tasks.taskEntries = ae.tasks;
|
||||
((EntityLiving) objE).targetTasks.taskEntries = ae.targetTasks;
|
||||
injEntityLivingBase.setObject(objE);
|
||||
injEntityLivingBase.setField("ignoreCollisions", false);
|
||||
injEntityLivingBase.setObject(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
trackedEntities.remove(new ChunkCoordinates(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
public static class AffectedEntity {
|
||||
|
||||
public final UUID eUUID;
|
||||
public List<EntityAITasks.EntityAITaskEntry> tasks;
|
||||
public List<EntityAITasks.EntityAITaskEntry> targetTasks;
|
||||
|
||||
public AffectedEntity(UUID eUUID,
|
||||
List<EntityAITasks.EntityAITaskEntry> tasks,
|
||||
List<EntityAITasks.EntityAITaskEntry> targetTasks) {
|
||||
this.eUUID = eUUID;
|
||||
this.tasks = tasks;
|
||||
this.targetTasks = targetTasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AffectedEntity that = (AffectedEntity) o;
|
||||
return !(eUUID != null ? !eUUID.equals(that.eUUID) : that.eUUID != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return eUUID != null ? eUUID.hashCode() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import java.util.Map;
|
||||
* 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<Entity, Float> tracked = new HashMap<Entity, Float>();
|
||||
|
||||
@@ -48,8 +48,6 @@ public class TileArcanePackager extends TileJarFillable implements IInventory, I
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
super.readFromNBT(compound);
|
||||
|
||||
redstoneState = compound.getBoolean("");
|
||||
|
||||
contents = new ItemStack[getSizeInventory()];
|
||||
NBTTagList list = compound.getTagList("Items", 10);
|
||||
|
||||
|
||||
@@ -592,7 +592,7 @@ public class TileAuraPylon extends SynchronizedTileEntity implements IAspectCont
|
||||
|
||||
@Override
|
||||
public int getMinimumSuction() {
|
||||
return 128;
|
||||
return 64;
|
||||
}
|
||||
|
||||
//Individual.
|
||||
|
||||
@@ -48,10 +48,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* HellFirePvP@Admin
|
||||
* Date: 22.04.2016 / 21:42
|
||||
* on Gadomancy
|
||||
* TileEssentiaCompressor
|
||||
* 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 HellFirePvP @ 22.04.2016 21:42
|
||||
*/
|
||||
public class TileEssentiaCompressor extends SynchronizedTileEntity implements IAspectSource, IEssentiaTransport {
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package makeo.gadomancy.common.events;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import makeo.gadomancy.common.aura.AuraEffects;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAIShutdown;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAuraPylon;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
@@ -11,6 +12,7 @@ import makeo.gadomancy.common.familiar.FamiliarAIController_Old;
|
||||
import makeo.gadomancy.common.utils.MiscUtils;
|
||||
import makeo.gadomancy.common.utils.Vector3;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.boss.IBossDisplayData;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -82,8 +84,13 @@ public class EventHandlerEntity {
|
||||
|
||||
@SubscribeEvent
|
||||
public void on(LivingDeathEvent event) {
|
||||
if (!event.entity.worldObj.isRemote && event.entityLiving instanceof EntityPlayer) {
|
||||
TCMazeHandler.closeSession((EntityPlayer) event.entityLiving, false);
|
||||
if (!event.entity.worldObj.isRemote) {
|
||||
if(event.entityLiving instanceof EntityPlayer) {
|
||||
TCMazeHandler.closeSession((EntityPlayer) event.entityLiving, false);
|
||||
}
|
||||
if(event.entityLiving instanceof EntityLiving) {
|
||||
TileAIShutdown.removeTrackedEntity((EntityLiving) event.entityLiving);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAIShutdown;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
|
||||
@@ -227,6 +228,9 @@ public class EventHandlerWorld {
|
||||
((TileNodeManipulator) te).breakMultiblock();
|
||||
}
|
||||
}
|
||||
if (event.block == RegisteredBlocks.blockStoneMachine && event.blockMetadata == 5) {
|
||||
TileAIShutdown.removeTrackedEntities(event.world, event.x, event.y, event.z);
|
||||
}
|
||||
if (event.world.provider.dimensionId == ModConfig.dimOuterId) {
|
||||
if(event.block == ConfigBlocks.blockEldritchNothing) {
|
||||
if(event.getPlayer().capabilities.isCreativeMode && MiscUtils.isANotApprovedOrMisunderstoodPersonFromMoreDoor(event.getPlayer())) return;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package makeo.gadomancy.common.registration;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.ai.EntityAIBase;
|
||||
import net.minecraft.entity.ai.EntityAIEatGrass;
|
||||
import net.minecraft.entity.passive.EntitySheep;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
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
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 08.06.2016 / 23:12
|
||||
*/
|
||||
public class AIShutdownWhitelist {
|
||||
|
||||
private AIShutdownWhitelist() {}
|
||||
|
||||
private static Map<Class<? extends EntityLiving>, List<Class<? extends EntityAIBase>>> whitelistedAI =
|
||||
new HashMap<Class<? extends EntityLiving>, List<Class<? extends EntityAIBase>>>();
|
||||
|
||||
public static void whitelistAIClass(Class<? extends EntityLiving> entityClass, Class<? extends EntityAIBase> aiClass) {
|
||||
if(!whitelistedAI.containsKey(entityClass)) {
|
||||
whitelistedAI.put(entityClass, new LinkedList<Class<? extends EntityAIBase>>());
|
||||
}
|
||||
whitelistedAI.get(entityClass).add(aiClass);
|
||||
}
|
||||
|
||||
public static void whitelistAIClass(EntityLiving entity, Class<? extends EntityAIBase> aiClass) {
|
||||
whitelistAIClass(entity.getClass(), aiClass);
|
||||
}
|
||||
|
||||
public static List<Class<? extends EntityAIBase>> getWhitelistedAIClasses(EntityLiving entity) {
|
||||
if(!whitelistedAI.containsKey(entity.getClass())) return Lists.newArrayList();
|
||||
return whitelistedAI.get(entity.getClass());
|
||||
}
|
||||
|
||||
static {
|
||||
whitelistAIClass(EntitySheep.class, EntityAIEatGrass.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,6 +128,7 @@ public class RegisteredBlocks {
|
||||
registerTile(TileArcanePackager.class);
|
||||
registerTile(TileKnowledgeBook.class);
|
||||
registerTile(TileEssentiaCompressor.class);
|
||||
registerTile(TileAIShutdown.class);
|
||||
}
|
||||
|
||||
private static void registerTile(Class<? extends TileEntity> tile, String name) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package makeo.gadomancy.common.registration;
|
||||
|
||||
import makeo.gadomancy.common.utils.MultiblockHelper;
|
||||
import net.minecraft.init.Blocks;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,7 @@ import thaumcraft.common.config.ConfigBlocks;
|
||||
* Created by HellFirePvP @ 27.10.2015 14:05
|
||||
*/
|
||||
public class RegisteredMultiblocks {
|
||||
|
||||
public static final MultiblockHelper.MultiblockPattern incompleteNodeManipulatorMultiblock = new MultiblockHelper.MultiblockPattern(RegisteredBlocks.blockNodeManipulator, 5)
|
||||
.addBlock(0, 2, 0, RegisteredBlocks.blockNode, 0).addBlock(0, 1, 0, RegisteredBlocks.blockStoneMachine, 0)
|
||||
.addBlock(1, 0, 1, ConfigBlocks.blockCosmeticSolid, 15).addBlock(-1, 0, 1, ConfigBlocks.blockCosmeticSolid, 15).addBlock(-1, 0, -1, ConfigBlocks.blockCosmeticSolid, 15).addBlock(1, 0, -1, ConfigBlocks.blockCosmeticSolid, 15)
|
||||
@@ -40,4 +42,15 @@ public class RegisteredMultiblocks {
|
||||
.addBlock(0, -1, 0, RegisteredBlocks.blockAuraPylon, 0)
|
||||
.addBlock(0, -2, 0, RegisteredBlocks.blockAuraPylon, 0)
|
||||
.addBlock(0, -3, 0, RegisteredBlocks.blockAuraPylon, 0);
|
||||
|
||||
public static final MultiblockHelper.MultiblockPattern aiShutdownPattern = new MultiblockHelper.MultiblockPattern(RegisteredBlocks.blockStoneMachine, 5);
|
||||
|
||||
static {
|
||||
for (int xx = -3; xx <= 3; xx++) {
|
||||
for (int zz = -3; zz <= -3; zz++) {
|
||||
aiShutdownPattern.addBlock(xx, 1, zz, Blocks.grass, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,12 +3,16 @@ package makeo.gadomancy.coremod;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -25,6 +29,7 @@ public class GadomancyTransformer extends AccessTransformer {
|
||||
public static final String NAME_NODE_RENDERER = "thaumcraft.client.renderers.tile.TileNodeRenderer";
|
||||
public static final String NAME_RENDER_EVENT_HANDLER = "thaumcraft.client.lib.RenderEventHandler";
|
||||
public static final String NAME_NEI_ITEMPANEL = "codechicken.nei.ItemPanel";
|
||||
public static final String NAME_ENTITY_LIVING_BASE = "net.minecraft.entity.EntityLivingBase";
|
||||
|
||||
public GadomancyTransformer() throws IOException {}
|
||||
|
||||
@@ -32,7 +37,8 @@ public class GadomancyTransformer extends AccessTransformer {
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
boolean needsTransform = transformedName.equalsIgnoreCase(NAME_ENCHANTMENT_HELPER) ||
|
||||
name.equalsIgnoreCase(NAME_WANDMANAGER) || name.equalsIgnoreCase(NAME_NODE_RENDERER)
|
||||
|| name.equalsIgnoreCase(NAME_RENDER_EVENT_HANDLER) || name.equals(NAME_NEI_ITEMPANEL);
|
||||
|| name.equalsIgnoreCase(NAME_RENDER_EVENT_HANDLER) || name.equals(NAME_NEI_ITEMPANEL) ||
|
||||
name.equalsIgnoreCase(NAME_ENTITY_LIVING_BASE);
|
||||
if(!needsTransform) return super.transform(name, transformedName, bytes);
|
||||
|
||||
FMLLog.info("[GadomancyTransformer] Transforming " + name + ": " + transformedName);
|
||||
@@ -136,6 +142,46 @@ public class GadomancyTransformer extends AccessTransformer {
|
||||
mn.instructions = newInstructions;
|
||||
}
|
||||
}
|
||||
} else if(name.equalsIgnoreCase(NAME_ENTITY_LIVING_BASE)) {
|
||||
FieldNode fn = new FieldNode(Opcodes.ACC_PUBLIC, "ignoreCollisions", Type.BOOLEAN_TYPE.getDescriptor(), null, true);
|
||||
node.fields.add(fn);
|
||||
|
||||
for(MethodNode mn : node.methods) {
|
||||
if(mn.name.equals("func_70636_d") || mn.name.equals("onLivingUpdate")) {
|
||||
AbstractInsnNode indexNode = null; //To insert after
|
||||
Label foundJumpLabel = null; //The jump in case we don't do collisions
|
||||
|
||||
for (int i = 0; i < mn.instructions.size() - 3; i++) {
|
||||
AbstractInsnNode inNode = mn.instructions.get(i);
|
||||
if(!(inNode instanceof FieldInsnNode)) continue;
|
||||
if(!((FieldInsnNode) inNode).name.equals("field_70170_p") &&
|
||||
!((FieldInsnNode) inNode).name.equals("worldObj")) continue;
|
||||
|
||||
inNode = mn.instructions.get(i + 1);
|
||||
if(!(inNode instanceof FieldInsnNode)) continue;
|
||||
if(!((FieldInsnNode) inNode).name.equals("field_72995_K") &&
|
||||
!((FieldInsnNode) inNode).name.equals("isRemote")) continue;
|
||||
|
||||
inNode = mn.instructions.get(i + 2);
|
||||
if(!(inNode instanceof JumpInsnNode)) continue;
|
||||
if(inNode.getOpcode() != Opcodes.IFNE) continue;
|
||||
foundJumpLabel = ((JumpInsnNode) inNode).label.getLabel();
|
||||
|
||||
//Index where we have to place our handling after.
|
||||
indexNode = inNode;
|
||||
}
|
||||
|
||||
if(indexNode == null || foundJumpLabel == null) {
|
||||
FMLLog.bigWarning("Could not add doCollisions to EntityLivingBase!");
|
||||
} else {
|
||||
InsnList addingList = new InsnList();
|
||||
addingList.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
addingList.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "ignoreCollisions", Type.BOOLEAN_TYPE.getDescriptor()));
|
||||
addingList.add(new JumpInsnNode(Opcodes.IFNE, new LabelNode(foundJumpLabel)));
|
||||
mn.instructions.insert(indexNode, addingList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
Reference in new issue
Block a user