mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-19 03:39:13 +00:00
Added basic block protector
This commit is contained in:
1 parent
acb2f07f45
commit
6edacd88a6
5 files changed
+205
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package makeo.gadomancy.common.blocks;
|
||||
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileManipulationFocus;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileManipulatorPillar;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
@@ -70,6 +71,8 @@ public class BlockStoneMachine extends Block {
|
||||
} else {
|
||||
return pedestalTopIcon;
|
||||
}
|
||||
} else if(metadata == 2) {
|
||||
return pedestalTopIcon;
|
||||
}
|
||||
|
||||
return super.getIcon(side, metadata);
|
||||
@@ -77,13 +80,14 @@ public class BlockStoneMachine extends Block {
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(int metadata) {
|
||||
return metadata == 15 || metadata == 0 || metadata == 1;
|
||||
return metadata == 15 || metadata == 0 || metadata == 1 || metadata == 2;
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,6 +108,8 @@ public class BlockStoneMachine extends Block {
|
||||
return new TileManipulationFocus();
|
||||
} else if(metadata == 1) {
|
||||
return new TilePedestal();
|
||||
} else if(metadata == 2) {
|
||||
return new TileBlockProtector();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package makeo.gadomancy.common.blocks.tiles;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import thaumcraft.api.ThaumcraftApiHelper;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.aspects.IAspectSource;
|
||||
import thaumcraft.api.aspects.IEssentiaTransport;
|
||||
import thaumcraft.common.tiles.TileJarFillable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 makeo @ 08.11.2015 17:36
|
||||
*/
|
||||
public class TileBlockProtector extends TileJarFillable {
|
||||
private static final int UPDATE_TICKS = 20;
|
||||
private static final int MAX_RANGE = 10;
|
||||
private static final int SATURATION = 0;
|
||||
private static final Aspect ASPECT = Aspect.ORDER;
|
||||
|
||||
private int range = 0;
|
||||
private int saturation = 0;
|
||||
private int count = 0;
|
||||
|
||||
public TileBlockProtector() {
|
||||
maxAmount = 16;
|
||||
aspectFilter = ASPECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (!protectors.contains(this)) {
|
||||
protectors.add(this);
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
if (++count % 5 == 0 && amount < maxAmount) {
|
||||
fillJar();
|
||||
}
|
||||
|
||||
if (count % UPDATE_TICKS == 0) {
|
||||
if (saturation > 0) {
|
||||
saturation--;
|
||||
return;
|
||||
}
|
||||
|
||||
if(takeFromContainer(ASPECT, 1)) {
|
||||
if(range < MAX_RANGE) {
|
||||
range++;
|
||||
}
|
||||
saturation = SATURATION;
|
||||
} else if(range > 0) {
|
||||
range--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fillJar() {
|
||||
TileEntity te = ThaumcraftApiHelper.getConnectableTile(this.worldObj, this.xCoord, this.yCoord, this.zCoord, ForgeDirection.DOWN);
|
||||
if (te != null) {
|
||||
IEssentiaTransport ic = (IEssentiaTransport) te;
|
||||
if (!ic.canOutputTo(ForgeDirection.UP)) {
|
||||
return;
|
||||
}
|
||||
Aspect ta = null;
|
||||
if (this.aspectFilter != null) {
|
||||
ta = this.aspectFilter;
|
||||
} else if ((this.aspect != null) && (this.amount > 0)) {
|
||||
ta = this.aspect;
|
||||
} else if ((ic.getEssentiaAmount(ForgeDirection.UP) > 0) &&
|
||||
(ic.getSuctionAmount(ForgeDirection.UP) < getSuctionAmount(ForgeDirection.DOWN)) && (getSuctionAmount(ForgeDirection.DOWN) >= ic.getMinimumSuction())) {
|
||||
ta = ic.getEssentiaType(ForgeDirection.UP);
|
||||
}
|
||||
if ((ta != null) && (ic.getSuctionAmount(ForgeDirection.UP) < getSuctionAmount(ForgeDirection.DOWN))) {
|
||||
addToContainer(ta, ic.takeEssentia(ta, 1, ForgeDirection.UP));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumSuction() {
|
||||
return super.getMinimumSuction() * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuctionAmount(ForgeDirection loc) {
|
||||
return super.getSuctionAmount(loc) * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectable(ForgeDirection face) {
|
||||
return face == ForgeDirection.DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputFrom(ForgeDirection face) {
|
||||
return face == ForgeDirection.DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutputTo(ForgeDirection face) {
|
||||
return face == ForgeDirection.DOWN;
|
||||
}
|
||||
|
||||
private static List<TileBlockProtector> protectors = new ArrayList<TileBlockProtector>();
|
||||
|
||||
public static boolean isSpotProtected(World world, double x, double y, double z) {
|
||||
for (int i = 0; i < protectors.size(); i++) {
|
||||
TileBlockProtector protector = protectors.get(i);
|
||||
if (protector.isInvalid()) {
|
||||
protectors.remove(i);
|
||||
i--;
|
||||
} else if (protector.worldObj.isRemote == world.isRemote
|
||||
&& isSpotProtected(protector, x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSpotProtected(TileBlockProtector tile, double x, double y, double z) {
|
||||
return tile.getDistanceFrom(x, y, z) < tile.range * tile.range;
|
||||
}
|
||||
}
|
||||
@@ -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.TileBlockProtector;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
@@ -12,17 +13,26 @@ import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.GolemEnumHelper;
|
||||
import makeo.gadomancy.common.utils.JarMultiblockHandler;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.boss.EntityDragon;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.event.world.ExplosionEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import thaumcraft.common.items.wands.ItemWandCasting;
|
||||
import thaumcraft.common.tiles.TileJarFillable;
|
||||
@@ -39,6 +49,14 @@ import java.util.Map;
|
||||
* Created by makeo @ 05.07.2015 13:20
|
||||
*/
|
||||
public class EventHandlerWorld {
|
||||
private Entity lastUpdated;
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void on(LivingEvent.LivingUpdateEvent e) {
|
||||
if(!e.entityLiving.worldObj.isRemote) {
|
||||
lastUpdated = e.entityLiving;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public void on(WorldEvent.Load e) {
|
||||
@@ -50,6 +68,46 @@ public class EventHandlerWorld {
|
||||
|
||||
TCMazeHandler.init();
|
||||
}
|
||||
|
||||
GameRules rules = e.world.getGameRules();
|
||||
rules.theGameRules.put("mobGriefing", new ValueOverride(this, String.valueOf(rules.getGameRuleBooleanValue("mobGriefing"))));
|
||||
}
|
||||
|
||||
private static class ValueOverride extends GameRules.Value {
|
||||
private final EventHandlerWorld handler;
|
||||
public ValueOverride(EventHandlerWorld handler, String value) {
|
||||
super(value);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGameRuleBooleanValue() {
|
||||
boolean mobGriefing = super.getGameRuleBooleanValue();
|
||||
if(mobGriefing) {
|
||||
Entity lastUpdated = handler.lastUpdated;
|
||||
if(lastUpdated != null) {
|
||||
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
|
||||
for(StackTraceElement element : elements) {
|
||||
if(element.getClassName().equals(EntityLivingBase.class.getName())
|
||||
&& (element.getMethodName().equals("func_70071_h") || element.getMethodName().equals("onUpdate"))) {
|
||||
return !TileBlockProtector.isSpotProtected(lastUpdated.worldObj, lastUpdated.posX, lastUpdated.posY, lastUpdated.posZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mobGriefing;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void on(ExplosionEvent.Start e) {
|
||||
Explosion expl = e.explosion;
|
||||
if(expl.isSmoking && TileBlockProtector.isSpotProtected(e.world, expl.explosionX, expl.explosionY, expl.explosionZ)) {
|
||||
//why?
|
||||
//expl.isSmoking = false;
|
||||
e.setCanceled(true);
|
||||
e.world.newExplosion(expl.exploder, expl.explosionX, expl.explosionY, expl.explosionZ, expl.explosionSize, expl.isFlaming, false);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
|
||||
@@ -100,6 +100,7 @@ public class RegisteredBlocks {
|
||||
registerTile(TileManipulatorPillar.class);
|
||||
registerTile(TileManipulationFocus.class);
|
||||
registerTile(TileAdditionalEldritchPortal.class);
|
||||
registerTile(TileBlockProtector.class);
|
||||
}
|
||||
|
||||
private static void registerTile(Class<? extends TileEntity> tile, String name) {
|
||||
|
||||
Reference in new issue
Block a user