Skip to content

Commit

Permalink
Move item setting to populateDefaultEquipmentSlots
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrbysco committed Jan 15, 2024
1 parent 15e4b87 commit 26e35bf
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class CymbalHusk extends Husk implements IInstrumentalMobs {

public CymbalHusk(EntityType<? extends CymbalHusk> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.CYMBAL.get()));
this.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(InstrumentalRegistry.CYMBAL.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setDropChance(EquipmentSlot.OFFHAND, getDropChance());
}

@Override
Expand Down Expand Up @@ -80,7 +76,11 @@ public boolean isClapping() {
}

@Override
protected void populateDefaultEquipmentSlots(RandomSource p_219165_, DifficultyInstance p_219166_) {
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance difficultyInstance) {
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.CYMBAL.get()));
this.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(InstrumentalRegistry.CYMBAL.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setDropChance(EquipmentSlot.OFFHAND, getDropChance());
}

class AttackTurtleEggGoal extends RemoveBlockGoal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
import com.mrbysco.instrumentalmobs.registration.InstrumentalRegistry;
import com.mrbysco.instrumentalmobs.registration.InstrumentalSounds;
import com.mrbysco.instrumentalmobs.utils.InstrumentHelper;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.RandomSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import org.jetbrains.annotations.Nullable;

public class FrenchHornCreeper extends Creeper implements IInstrumentalMobs {

public FrenchHornCreeper(EntityType<? extends FrenchHornCreeper> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.FRENCH_HORN.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
}

@Override
Expand All @@ -32,4 +37,21 @@ public void explodeCreeper() {
this.spawnLingeringCloud();
}
}

@Override
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance difficultyInstance) {
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.FRENCH_HORN.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
}

public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance,
MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData,
@Nullable CompoundTag compoundTag) {
RandomSource randomSource = serverLevelAccessor.getRandom();
spawnGroupData = super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag);

this.populateDefaultEquipmentSlots(randomSource, difficultyInstance);

return spawnGroupData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import com.mrbysco.instrumentalmobs.registration.InstrumentalRegistry;
import com.mrbysco.instrumentalmobs.registration.InstrumentalSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.RandomSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.goal.FloatGoal;
import net.minecraft.world.entity.ai.goal.LeapAtTargetGoal;
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
Expand All @@ -24,17 +29,15 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class MaracaSpider extends Spider implements IInstrumentalMobs {
private static final EntityDataAccessor<Boolean> ATTACKING = SynchedEntityData.<Boolean>defineId(MaracaSpider.class, EntityDataSerializers.BOOLEAN);

public MaracaSpider(EntityType<? extends MaracaSpider> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.MARACA.get()));
this.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(InstrumentalRegistry.MARACA.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setDropChance(EquipmentSlot.OFFHAND, getDropChance());
}

@Override
Expand Down Expand Up @@ -121,4 +124,23 @@ protected void playStepSound(BlockPos pos, BlockState blockIn) {
this.playSound(SoundEvents.SPIDER_STEP, 0.15F, 1.0F);
this.playSound(InstrumentalSounds.MARACA_SOUND.get(), 0.15F, 1.0F);
}

@Override
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance difficultyInstance) {
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.MARACA.get()));
this.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(InstrumentalRegistry.MARACA.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setDropChance(EquipmentSlot.OFFHAND, getDropChance());
}

public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance,
MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData,
@Nullable CompoundTag compoundTag) {
RandomSource randomSource = serverLevelAccessor.getRandom();
spawnGroupData = super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag);

this.populateDefaultEquipmentSlots(randomSource, difficultyInstance);

return spawnGroupData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import com.mrbysco.instrumentalmobs.entities.projectiles.SoundWaves;
import com.mrbysco.instrumentalmobs.registration.InstrumentalRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Difficulty;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
Expand All @@ -21,7 +24,9 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

import java.util.EnumSet;

Expand All @@ -30,8 +35,6 @@ public class MicrophoneGhast extends Ghast implements IInstrumentalMobs {

public MicrophoneGhast(EntityType<? extends MicrophoneGhast> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(InstrumentalRegistry.MICROPHONE.get()));
this.setDropChance(EquipmentSlot.HEAD, getDropChance());
}

@Override
Expand All @@ -57,6 +60,23 @@ public boolean isSinging() {
return (Boolean) this.getEntityData().get(SINGING);
}

@Override
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance difficultyInstance) {
this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(InstrumentalRegistry.MICROPHONE.get()));
this.setDropChance(EquipmentSlot.HEAD, getDropChance());
}

public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance,
MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData,
@Nullable CompoundTag compoundTag) {
RandomSource randomSource = serverLevelAccessor.getRandom();
spawnGroupData = super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag);

this.populateDefaultEquipmentSlots(randomSource, difficultyInstance);

return spawnGroupData;
}

static class VoiceAttackGoal extends Goal {
private final MicrophoneGhast parentEntity;
public int attackTimer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class TrumpetSkeleton extends Skeleton implements IInstrumentalMobs, IIns

public TrumpetSkeleton(EntityType<? extends TrumpetSkeleton> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.TRUMPET.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
}

@Override
Expand Down Expand Up @@ -79,7 +77,10 @@ public boolean isPlayingInstrument() {
return (Boolean) this.getEntityData().get(DOOTING);
}


@Override
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance instance) {
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance difficultyInstance) {
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.TRUMPET.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import com.mrbysco.instrumentalmobs.platform.Services;
import com.mrbysco.instrumentalmobs.registration.InstrumentalRegistry;
import com.mrbysco.instrumentalmobs.registration.InstrumentalSounds;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.RandomSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.goal.FloatGoal;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
Expand All @@ -22,6 +27,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

Expand All @@ -32,14 +38,12 @@ public class TubaEnderman extends EnderMan implements IInstrumentalMobs {

public TubaEnderman(EntityType<? extends TubaEnderman> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.TUBA.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setCombatTask();
this.reassessWeaponGoal();
}

private final InstrumentAttackGoal playOnCollideGoal = new InstrumentAttackGoal(this, 1.0D, false, InstrumentalSounds.TUBA_SOUND::get);

private void setCombatTask() {
private void reassessWeaponGoal() {
if (this.level() != null && !this.level().isClientSide) {
this.goalSelector.removeGoal(this.playOnCollideGoal);
ItemStack itemstack = this.getMainHandItem();
Expand Down Expand Up @@ -90,6 +94,38 @@ private boolean isLookingAtMe(Player player) {
}
}

@Override
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance difficultyInstance) {
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(InstrumentalRegistry.TUBA.get()));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
}

public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance,
MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData,
@Nullable CompoundTag compoundTag) {
RandomSource randomSource = serverLevelAccessor.getRandom();
spawnGroupData = super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag);

this.populateDefaultEquipmentSlots(randomSource, difficultyInstance);
this.reassessWeaponGoal();

return spawnGroupData;
}

@Override
public void readAdditionalSaveData(CompoundTag compoundTag) {
super.readAdditionalSaveData(compoundTag);
this.reassessWeaponGoal();
}

@Override
public void setItemSlot(EquipmentSlot equipmentSlot, ItemStack itemStack) {
super.setItemSlot(equipmentSlot, itemStack);
if (!this.level().isClientSide) {
this.reassessWeaponGoal();
}
}

static class LookForPlayerGOal extends NearestAttackableTargetGoal<Player> {
private final TubaEnderman enderman;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public class XylophoneSkeleton extends Skeleton implements IInstrumentalMobs, II

public XylophoneSkeleton(EntityType<? extends XylophoneSkeleton> type, Level level) {
super(type, level);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.BONE));
this.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(Items.BONE));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setDropChance(EquipmentSlot.OFFHAND, getDropChance());
}

@Override
Expand Down Expand Up @@ -84,5 +80,9 @@ public boolean isPlayingInstrument() {

@Override
protected void populateDefaultEquipmentSlots(RandomSource randomSource, DifficultyInstance instance) {
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.BONE));
this.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(Items.BONE));
this.setDropChance(EquipmentSlot.MAINHAND, getDropChance());
this.setDropChance(EquipmentSlot.OFFHAND, getDropChance());
}
}

0 comments on commit 26e35bf

Please sign in to comment.