Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/circuitlord/reactivemusic/PlayerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void processRealGain() {
/* public int getFramesPlayed() {
return player == null ? 0 : player.getFrames();
}*/
@SuppressWarnings("removal")
public void forceKill() {
try {
resetPlayer();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/circuitlord/reactivemusic/SongPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public final class SongPicker {

public static boolean wasSleeping = false;

public static long lastCombatTime = -1;
public static final long COMBAT_TIMEOUT = 200; // ticks (5 seconds)

static {

for (Field field : BIOME_TAG_FIELDS) {
Expand Down Expand Up @@ -243,6 +246,10 @@ public static void tickEventMap() {

}

// Check if player was recently in combat (attacked or was attacked)
boolean inCombat = (world.getTime() - lastCombatTime) < COMBAT_TIMEOUT;
songpackEventMap.put(SongpackEventType.COMBAT, inCombat);


//songpackEventMap.put(SongpackEventType.HOSTILE_MOBS, aggroMobsCount >= 4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public enum SongpackEventType {

NEARBY_MOBS,

COMBAT,




Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package circuitlord.reactivemusic.mixin;

import circuitlord.reactivemusic.SongPicker;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin {
@Shadow @Final private static Logger LOGGER;

@Inject(method = "attack", at = @At("HEAD"))
private void onAttack(Entity target, CallbackInfo ci) {
if ((Object)this instanceof ClientPlayerEntity) {
ClientPlayerEntity player = (ClientPlayerEntity)(Object)this;
World world = player.getWorld();
LOGGER.info("Player attacked: {} at time: {}", player.getName().getString(), world.getTime());
SongPicker.lastCombatTime = world.getTime();
}
}
@Inject(method = "damage", at = @At("HEAD"))
private void onDamage(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
PlayerEntity player = (PlayerEntity) (Object) this;
World playerWorld = player.getWorld();
// cause of source
if (source.getAttacker() != null) {
SongPicker.lastCombatTime = playerWorld.getTime();
}
}
}
1 change: 1 addition & 0 deletions src/main/java/rm_javazoom/jl/player/PlayerApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author Mat McGowan
* @since 0.0.8
*/
@SuppressWarnings("removal")
public class PlayerApplet extends Applet implements Runnable
{
static public final String AUDIO_PARAMETER = "audioURL";
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/reactivemusic.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"MinecraftClientMixin",
"MusicTrackerMixin",
"BossBarHudAccessor",
"SoundManagerMixin"
"SoundManagerMixin",
"PlayerEntityMixin"
]
}