Skip to content

Commit

Permalink
Make hidebehinds retaliate when attacked while unable to attack you d…
Browse files Browse the repository at this point in the history
…ue to light, and make them immortal to attacks during this time. Also make hidebehinds despawn during the daytime (Fixes #13)
  • Loading branch information
itsmeow committed May 24, 2021
1 parent 295f3e9 commit c2b36fb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Forge
mc_version = 1.15.2
forge_version = 31.2.50
mappings_version = 20210424
mappings_version = 20210523
mappings_channel = snapshot
mappings_mc_version = 1.15.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.entity.*;
import net.minecraft.entity.ai.RandomPositionGenerator;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.ai.goal.HurtByTargetGoal;
import net.minecraft.entity.ai.goal.SwimGoal;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
Expand All @@ -21,6 +22,8 @@
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.pathfinding.*;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -79,6 +82,22 @@ public boolean attackEntityFrom(DamageSource source, float amount) {
if(source.getTrueSource() == this.getAttackTarget() && this.attackSequenceTicks() > 0) {
this.setAttackSequenceTicks(0);
}
if (!world.isRemote()) {
boolean isImmediate = source.getImmediateSource() instanceof PlayerEntity;
PlayerEntity player = isImmediate ? (PlayerEntity) source.getImmediateSource() : (source.getTrueSource() instanceof PlayerEntity ? (PlayerEntity) source.getTrueSource() : null);
if (player != null) {
if (!this.isEntityAttackable(player)) {
// retaliate attacks if you can't chase due to light
if (!player.isCreative()) {
player.addPotionEffect(new EffectInstance(Effects.BLINDNESS, 15 * 20, 1));
if (player.getDistance(this) < 3)
player.attackEntityFrom(HIDEBEHIND, 1F);
}
HideFromTargetGoal.doTreeTick(this);
return false;
}
}
}
return super.attackEntityFrom(source, amount);
}

Expand Down Expand Up @@ -337,7 +356,11 @@ public void startExecuting() {

@Override
public void tick() {
this.hidebehind.getNavigator().clearPath();
doTreeTick(hidebehind);
}

public static void doTreeTick(EntityHidebehind hidebehind) {
hidebehind.getNavigator().clearPath();
boolean nearTree = false;
for(Direction dir : Direction.values()) {
if(!nearTree) {
Expand Down Expand Up @@ -392,6 +415,11 @@ protected void registerData() {
this.dataManager.register(ATTACK_SEQUENCE_TICKS, 0);
}

@Override
public boolean canDespawn(double range) {
return world.isDaytime() && super.canDespawn(range);
}

@Override
protected PathNavigator createNavigator(World world) {
return new HidebehindGroundNavigator(this, world);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void subscribe(IEventBus modBus) {
.defaultPlacement((t, w, e, p, r) -> w.getDifficulty() != Difficulty.PEACEFUL && MobEntity.canSpawnOn(t, w, e, p, r))
.egg(0x473123, 0xfff494)
.size(1F, 5.2F)
.despawn()
.variants(
new HidebehindVariant("black"),
new HidebehindVariant("coniferous"),
Expand Down

0 comments on commit c2b36fb

Please sign in to comment.