Skip to content

Commit

Permalink
add config option to respect visibility (fixes #83)
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ckscor3 committed Feb 29, 2020
1 parent ac26087 commit 2d48675
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 41 deletions.
1 change: 1 addition & 0 deletions Changelog v1.8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- New: The Mine-/Sentry Remote Access Tool GUI now shows explanatory tooltips when hovering over buttons
- New: The Mine-/Sentry Remote Access Tool now show whether a mine/sentry the player is looking at is bound to them on the hotbar (just like the Camera Monitor)
- New: Spanish translation (Thanks Ryo567!)
- New: Configuration option to account for invisibility (Sentries, Inventory Scanners, Lasers, etc. won't detect entities if they're invisible, config option is off by default)
- Change: The Username Logger now displays logged users in a scrollable list
- Change: The floor of Block Pockets is now solid (reactivate Block Pockets to fix this for already existing ones)
- Change: Slightly improve Reinforced (Stained) Glass textures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public class ConfigHandler {
public BooleanValue sayThanksMessage;
public DoubleValue alarmSoundVolume;
public DoubleValue cameraSpeed;
public BooleanValue respectInvisibility;

public ConfigHandler(ForgeConfigSpec.Builder builder)
ConfigHandler(ForgeConfigSpec.Builder builder)
{
allowCodebreakerItem = builder
.translation("config.securitycraft:isCodebreakerAllowed")
Expand Down Expand Up @@ -191,5 +192,10 @@ public ConfigHandler(ForgeConfigSpec.Builder builder)
.translation("config.securitycraft:cameraSpeed")
.comment("How fast can you rotate when mounted to a camera and holding W-A-S-D?")
.defineInRange("cameraSpeed", 2.0D, 0.0D, Double.MAX_VALUE);

respectInvisibility = builder
.translation("config.securitycraft:respectInvisibility")
.comment("Should the sentry/inventory scanner/laser block/etc. ignore players and entities that are invisible?")
.define("respect_invisibility", false);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.geforcemods.securitycraft.blocks;

import net.geforcemods.securitycraft.SCContent;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FlowingFluidBlock;
Expand Down Expand Up @@ -33,7 +32,7 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit

lEntity.extinguish();

if(!EntityUtils.doesMobHavePotionEffect(lEntity, Effects.FIRE_RESISTANCE))
if(!lEntity.isPotionActive(Effects.FIRE_RESISTANCE))
lEntity.addPotionEffect(SHORT_FIRE_RESISTANCE);

lEntity.heal(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.tileentity.InventoryScannerTileEntity;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void onEntityIntersected(World world, BlockPos pos, Entity entity)
if(connectedScanner == null)
return;

if(entity instanceof PlayerEntity)
if(entity instanceof PlayerEntity && !EntityUtils.isInvisible((PlayerEntity)entity))
{
if(ModuleUtils.checkForModule(world, connectedScanner.getPos(), (PlayerEntity)entity, CustomModules.WHITELIST))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
Expand All @@ -32,7 +31,6 @@
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;

public class LaserFieldBlock extends OwnableBlock implements IIntersectable{

Expand All @@ -55,7 +53,7 @@ public VoxelShape getCollisionShape(BlockState blockState, IBlockReader world, B
@Override
public void onEntityIntersected(World world, BlockPos pos, Entity entity)
{
if(!world.isRemote && entity instanceof LivingEntity && !EntityUtils.doesMobHavePotionEffect((LivingEntity) entity, ForgeRegistries.POTIONS.getValue(new ResourceLocation("minecraft:invisibility"))))
if(!world.isRemote && entity instanceof LivingEntity && !EntityUtils.isInvisible((LivingEntity)entity))
{
for(Direction facing : Direction.values())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import net.geforcemods.securitycraft.entity.SentryEntity;
import net.geforcemods.securitycraft.entity.SentryEntity.SentryMode;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.Goal;
Expand Down Expand Up @@ -35,7 +36,7 @@ public boolean shouldExecute()

if(potentialTarget == null)
return false;
else if(sentry.isTargetingWhitelistedPlayer(potentialTarget))
else if(sentry.isTargetingWhitelistedPlayer(potentialTarget) || EntityUtils.isInvisible(potentialTarget))
{
sentry.setAttackTarget(null);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import net.geforcemods.securitycraft.entity.SentryEntity;
import net.geforcemods.securitycraft.entity.SentryEntity.SentryMode;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal;
Expand All @@ -28,7 +29,7 @@ public TargetNearestPlayerOrMobGoal(SentryEntity sentry)
@Override
public boolean shouldExecute()
{
List<LivingEntity> list = goalOwner.world.<LivingEntity>getEntitiesWithinAABB(targetClass, getTargetableArea(getTargetDistance()), e -> true);
List<LivingEntity> list = goalOwner.world.<LivingEntity>getEntitiesWithinAABB(targetClass, getTargetableArea(getTargetDistance()), e -> !EntityUtils.isInvisible(e));

if(list.isEmpty())
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public ClaymoreTileEntity()

@Override
public void tick() {
if(getWorld().isRemote)
return;
else{
if(!getWorld().isRemote)
{
if(getWorld().getBlockState(getPos()).get(ClaymoreBlock.DEACTIVATED))
return;

Expand All @@ -63,7 +62,7 @@ else if(dir == Direction.EAST)
else if(dir == Direction.WEST)
area = area.contract(ConfigHandler.CONFIG.claymoreRange.get(), -0, -0);

List<?> entities = getWorld().getEntitiesWithinAABB(LivingEntity.class, area);
List<?> entities = getWorld().getEntitiesWithinAABB(LivingEntity.class, area, e -> !EntityUtils.isInvisible(e));
Iterator<?> iterator = entities.iterator();
LivingEntity entity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.geforcemods.securitycraft.entity.IMSBombEntity;
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.geforcemods.securitycraft.util.PlayerUtils;
import net.geforcemods.securitycraft.util.WorldUtils;
Expand Down Expand Up @@ -69,8 +70,8 @@ private void launchMine() {
double range = ConfigHandler.CONFIG.imsRange.get();

AxisAlignedBB area = BlockUtils.fromBounds(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1).grow(range, range, range);
List<?> players = world.getEntitiesWithinAABB(PlayerEntity.class, area);
List<?> mobs = world.getEntitiesWithinAABB(MonsterEntity.class, area);
List<?> players = world.getEntitiesWithinAABB(PlayerEntity.class, area, e -> !EntityUtils.isInvisible(e));
List<?> mobs = world.getEntitiesWithinAABB(MonsterEntity.class, area, e -> !EntityUtils.isInvisible(e));
Iterator<?> playerIterator = players.iterator();
Iterator<?> mobIterator = mobs.iterator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.geforcemods.securitycraft.blocks.MotionActivatedLightBlock;
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.PlayerUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
Expand All @@ -26,8 +27,9 @@ public MotionActivatedLightTileEntity()
public boolean attackEntity(Entity entity) {
if(entity instanceof PlayerEntity && PlayerUtils.isPlayerMountedOnCamera((PlayerEntity)entity))
MotionActivatedLightBlock.toggleLight(world, pos, searchRadiusOption.asDouble(), getOwner(), false);
else if(entity instanceof LivingEntity && BlockUtils.getBlock(getWorld(), pos) == SCContent.MOTION_ACTIVATED_LIGHT.get() && !BlockUtils.getBlockProperty(getWorld(), getPos(), MotionActivatedLightBlock.LIT))
MotionActivatedLightBlock.toggleLight(world, pos, searchRadiusOption.asDouble(), getOwner(), true);
else if(entity instanceof LivingEntity && BlockUtils.getBlock(getWorld(), pos) == SCContent.MOTION_ACTIVATED_LIGHT.get())
MotionActivatedLightBlock.toggleLight(world, pos, searchRadiusOption.asDouble(), getOwner(), !EntityUtils.isInvisible((LivingEntity)entity)); //also automatically switches on/off based on if the entity turns (in-)visible


return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.geforcemods.securitycraft.blocks.PortableRadarBlock;
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.util.ClientUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.geforcemods.securitycraft.util.PlayerUtils;
import net.geforcemods.securitycraft.util.Utils;
Expand Down Expand Up @@ -39,7 +40,7 @@ public PortableRadarTileEntity()
//Using TileEntitySCTE.attacks() and the attackEntity() method to check for players. :3
@Override
public boolean attackEntity(Entity attacked) {
if (attacked instanceof PlayerEntity)
if (attacked instanceof PlayerEntity && !EntityUtils.isInvisible((PlayerEntity)attacked))
{
AxisAlignedBB area = new AxisAlignedBB(pos).grow(getAttackRange(), getAttackRange(), getAttackRange());
List<?> entities = world.getEntitiesWithinAABB(entityTypeToAttack(), area);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.geforcemods.securitycraft.blocks.ProtectoBlock;
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
Expand All @@ -24,7 +25,7 @@ public ProtectoTileEntity()

@Override
public boolean attackEntity(Entity entity){
if (entity instanceof LivingEntity) {
if (entity instanceof LivingEntity && !EntityUtils.isInvisible(((LivingEntity)entity))) {
if ((entity instanceof PlayerEntity && (getOwner().isOwner((PlayerEntity) entity) || (hasModule(CustomModules.WHITELIST) && ModuleUtils.getPlayersFromModule(world, pos, CustomModules.WHITELIST).contains(((LivingEntity) entity).getName().getFormattedText().toLowerCase())))) ||
entity instanceof ZombiePigmanEntity ||
(entity instanceof CreeperEntity && ((CreeperEntity) entity).func_225509_J__()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.ClientUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.geforcemods.securitycraft.util.PlayerUtils;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -44,7 +45,7 @@ public RetinalScannerTileEntity()

@Override
public void entityViewed(LivingEntity entity){
if(!world.isRemote && !BlockUtils.getBlockProperty(world, pos, RetinalScannerBlock.POWERED)){
if(!world.isRemote && !BlockUtils.getBlockProperty(world, pos, RetinalScannerBlock.POWERED) && !EntityUtils.isInvisible(entity)){
if(!(entity instanceof PlayerEntity) && !activatedByEntities.asBoolean())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.geforcemods.securitycraft.misc.CustomModules;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.ClientUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.geforcemods.securitycraft.util.PlayerUtils;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
Expand All @@ -33,7 +34,7 @@ public void entityViewed(LivingEntity entity)
BlockState upperState = world.getBlockState(pos);
BlockState lowerState = world.getBlockState(pos.down());

if(!world.isRemote && upperState.get(DoorBlock.HALF) == DoubleBlockHalf.UPPER)
if(!world.isRemote && upperState.get(DoorBlock.HALF) == DoubleBlockHalf.UPPER && !EntityUtils.isInvisible(entity))
{
if(!(entity instanceof PlayerEntity))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void resetTarget() {
* within range of the trophy
*/
private Entity getTarget() {
List<Entity> potentialTargets = new ArrayList<Entity>();
List<Entity> potentialTargets = new ArrayList<>();
AxisAlignedBB area = new AxisAlignedBB(pos).grow(range, range, range);

// Add all arrows and fireballs to the targets list. Could always add more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.geforcemods.securitycraft.network.client.ClearLoggerClient;
import net.geforcemods.securitycraft.network.client.UpdateLogger;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.EntityUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void logPlayers(){
private void addPlayer(PlayerEntity player) {
long timestamp = System.currentTimeMillis();

if(!getOwner().isOwner(player) && !hasPlayerName(player.getName().getFormattedText(), timestamp))
if(!getOwner().isOwner(player) && !EntityUtils.isInvisible(player) && !hasPlayerName(player.getName().getFormattedText(), timestamp))
{
for(int i = 0; i < players.length; i++)
{
Expand Down
24 changes: 7 additions & 17 deletions src/main/java/net/geforcemods/securitycraft/util/EntityUtils.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
package net.geforcemods.securitycraft.util;

import java.util.Iterator;

import net.geforcemods.securitycraft.ConfigHandler;
import net.geforcemods.securitycraft.api.IOwnable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class EntityUtils{

public static boolean doesMobHavePotionEffect(LivingEntity mob, Effect effect){
Iterator<EffectInstance> effects = mob.getActivePotionEffects().iterator();

while(effects.hasNext()){
String eName = effects.next().getEffectName();

if(eName.equals(effect.getName()))
return true;
}

return false;
}

public static boolean doesEntityOwn(Entity entity, World world, BlockPos pos)
{
if(entity instanceof PlayerEntity)
Expand All @@ -40,4 +25,9 @@ public static boolean doesPlayerOwn(PlayerEntity player, World world, BlockPos p

return te instanceof IOwnable && ((IOwnable)te).getOwner().isOwner(player);
}

public static boolean isInvisible(LivingEntity entity)
{
return ConfigHandler.CONFIG.respectInvisibility.get() && entity.isPotionActive(Effects.INVISIBILITY);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/securitycraft/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@
"config.securitycraft:checkForUpdates.tooltip": "Soll SecurityCraft nach Updates für den Mod mittels SecurityCraft's GitHub repo suchen?",
"config.securitycraft:maxAlarmRange": "Maximale Alarm Reichweite",
"config.securitycraft:maxAlarmRange.tooltip": "Was ist der maximale Wert der für die Reichweiten-Einstellung eines Alarms gesetzt werden kann? Beachte, dass dieser Wert durch die Ladedistanz von Chunks begrenzt sein kann. Höhere Werte können außerdem nicht fein eingestellt werden.",

"config.securitycraft:respectInvisibility": "Unsichtbarkeit berücksichtigen?",
"config.securitycraft:respectInvisibility.tooltip": "Soll das Geschütz/der Inventarscanner/Laser Block/etc. Spieler und Mobs ignorieren, die unsichtbar sind?",

"option.securitycraft.portable_radar.searchRadius": "Suchradius: #",
"option.securitycraft.portable_radar.searchRadius.description": "Der Radius, in dem der Radar sucht.",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/securitycraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@
"config.securitycraft:allowBlockClaim.tooltip": "Allow claiming unowned blocks?",
"config.securitycraft:maxAlarmRange": "Maximum Alarm Range",
"config.securitycraft:maxAlarmRange.tooltip": "What is the maximum value that can be set for an alarm's range option? Do note, that this may be limited by chunk loading distance. Higher values may also not be finetuneable.",
"config.securitycraft:respectInvisibility": "Respect invisibility?",
"config.securitycraft:respectInvisibility.tooltip": "Should the sentry/inventory scanner/laser block/etc. ignore players and entities that are invisible?",

"option.securitycraft.portable_radar.searchRadius": "Search radius: #",
"option.securitycraft.portable_radar.searchRadius.description": "The radius the radar searches in.",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/securitycraft/lang/es_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@
"config.securitycraft:allowBlockClaim.tooltip": "¿Permitir reclamar bloques sin propietario?",
"config.securitycraft:maxAlarmRange": "Alcance máximo de alarma",
"config.securitycraft:maxAlarmRange.tooltip": "¿Cuál es el máximo nivel de alcance que se puede establecer para la alarma? Recuerda, esto puede estar limitado por la distancia de carga del mapa. Los valores altos pueden dar problemas.",
"config.securitycraft:respectInvisibility": "¿Respetar invisibilidad?",
"config.securitycraft:respectInvisibility.tooltip": "¿Deberían las torretas/escáneres de inventario/bloques láser/etc. ignorar a jugadores y entidades que son invisibles?",

"option.securitycraft.portable_radar.searchRadius": "Radio de búsqueda: #",
"option.securitycraft.portable_radar.searchRadius.description": "Radio en el que busca el radar.",
Expand Down

0 comments on commit 2d48675

Please sign in to comment.