Skip to content

Commit

Permalink
Make wisps not be hostile in peaceful
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Oct 5, 2020
1 parent 359ef9e commit 42914b4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/dev/itsmeow/whisperwoods/entity/EntityWisp.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.Difficulty;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.IServerWorld;
import net.minecraft.world.World;
Expand All @@ -58,6 +59,7 @@ public class EntityWisp extends AnimalEntity implements IContainerEntity<EntityW
public static final DataParameter<Float> PASSIVE_SCALE = EntityDataManager.createKey(EntityWisp.class, DataSerializers.FLOAT);
public static final DataParameter<Integer> COLOR_VARIANT = EntityDataManager.createKey(EntityWisp.class, DataSerializers.VARINT);
protected ResourceLocation targetTexture;
private boolean shouldBeHostile = false;

protected EntityWisp(EntityType<? extends EntityWisp> entityType, World world) {
super(entityType, world);
Expand All @@ -79,6 +81,13 @@ protected void registerData() {

public void tick() {
super.tick();
if(this.isHostile && world.getDifficulty() == Difficulty.PEACEFUL) {
this.isHostile = false;
this.shouldBeHostile = true;
} else if(this.shouldBeHostile && world.getDifficulty() != Difficulty.PEACEFUL) {
this.isHostile = true;
this.shouldBeHostile = false;
}
int state = this.dataManager.get(ATTACK_STATE);
if(state == 0) {
this.setMotion(this.getMotion().mul(0.5D, 0.6D, 0.5D));
Expand Down Expand Up @@ -235,13 +244,15 @@ public void writeAdditional(CompoundNBT compound) {
super.writeAdditional(compound);
compound.putBoolean("is_hostile", isHostile);
compound.putInt("color_variant", this.dataManager.get(COLOR_VARIANT));
compound.putBoolean("should_be_hositle", this.shouldBeHostile);
}

@Override
public void readAdditional(CompoundNBT compound) {
super.readAdditional(compound);
this.isHostile = compound.getBoolean("is_hostile");
this.dataManager.set(COLOR_VARIANT, compound.getInt("color_variant"));
this.shouldBeHostile = compound.getBoolean("should_be_hostile");
}

@Override
Expand Down

0 comments on commit 42914b4

Please sign in to comment.