Skip to content

Commit

Permalink
add tag to define which entities cannot be invisible
Browse files Browse the repository at this point in the history
also reduce duplicate code in invisibility events
  • Loading branch information
bl4ckscor3 committed Feb 21, 2023
1 parent d3569ae commit a19bd36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/main/java/me/juancarloscp52/entropy/EntropyTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class EntropyTags {
public static final TagKey<EntityType<?>> IGNORED_BY_FORCEFIELD_AND_ENTITY_MAGNET = TagKey.of(Registries.ENTITY_TYPE.getKey(), new Identifier("entropy", "ignored_by_forcefield_and_entity_magnet"));
public static final TagKey<EntityType<?>> DO_NOT_LEVITATE = TagKey.of(Registries.ENTITY_TYPE.getKey(), new Identifier("entropy", "do_not_levitate"));
public static final TagKey<EntityType<?>> NOT_INVISIBLE = TagKey.of(Registries.ENTITY_TYPE.getKey(), new Identifier("entropy", "not_invisible"));
public static final TagKey<Block> NOT_REPLACED_BY_EVENTS = TagKey.of(Registries.BLOCK.getKey(), new Identifier("entropy", "not_replaced_by_events"));
public static final TagKey<Block> IGNORED_BY_MIDAS_TOUCH = TagKey.of(Registries.BLOCK.getKey(), new Identifier("entropy", "ignored_by_midas_touch"));
public static final TagKey<Block> VOID_SIGHT_BREAKS = TagKey.of(Registries.BLOCK.getKey(), new Identifier("entropy", "void_sight_breaks"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.List;

import me.juancarloscp52.entropy.Entropy;
import me.juancarloscp52.entropy.EntropyTags;
import me.juancarloscp52.entropy.events.AbstractTimedEvent;
import me.juancarloscp52.entropy.server.ServerEventHandler;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
Expand All @@ -31,11 +33,15 @@ public void tick() {
worlds.add(player.getWorld());
for(var world : worlds)
for(var entity : world.iterateEntities())
if(entity instanceof LivingEntity)
if(shouldBeInvisible(entity))
((LivingEntity)entity).addStatusEffect(new StatusEffectInstance(StatusEffects.INVISIBILITY, 2));
super.tick();
}

public boolean shouldBeInvisible(Entity entity) {
return entity instanceof LivingEntity && !entity.getType().isIn(EntropyTags.NOT_INVISIBLE);
}

@Override
public void end() {
this.hasEnded = true;
Expand All @@ -54,5 +60,5 @@ public short getDuration() {
public String type() {
return "invisibility";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,12 @@

package me.juancarloscp52.entropy.events.db;

import java.util.ArrayList;
import java.util.List;

import me.juancarloscp52.entropy.Entropy;
import me.juancarloscp52.entropy.events.AbstractTimedEvent;
import me.juancarloscp52.entropy.server.ServerEventHandler;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.Monster;
import net.minecraft.server.world.ServerWorld;

public class InvisibleHostileMobsEvent extends AbstractTimedEvent {

@Override
public void init() {
}

@Override
public void tick() {
ServerEventHandler eventHandler = Entropy.getInstance().eventHandler;
List<ServerWorld> worlds = new ArrayList<>();
for(var player : eventHandler.getActivePlayers())
if(!worlds.contains(player.getWorld()))
worlds.add(player.getWorld());
for(var world : worlds)
for(var entity : world.iterateEntities())
if(entity instanceof Monster && entity instanceof LivingEntity)
((LivingEntity)entity).addStatusEffect(new StatusEffectInstance(StatusEffects.INVISIBILITY, 2));
super.tick();
}

@Override
public void end() {
this.hasEnded = true;
}

@Override
public void render(MatrixStack matrixStack, float tickdelta) {
}

@Override
public short getDuration() {
return Entropy.getInstance().settings.baseEventDuration;
}

public class InvisibleHostileMobsEvent extends InvisibleEveryoneEvent {
@Override
public String type() {
return "invisibility";
public boolean shouldBeInvisible(Entity entity) {
return entity instanceof Monster && super.shouldBeInvisible(entity);
}

}

0 comments on commit a19bd36

Please sign in to comment.