Skip to content

Commit

Permalink
Merged 1.9.8 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz authored Feb 10, 2024
2 parents eae964c + 6fd507c commit 6a8bb11
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 175 deletions.
8 changes: 5 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- fixed compatibility crash with Tinkerer's Smithing (reported by @FLSoz)
- fixed game crash caused by Cursed Armor (reported by @GenericCherrySwitch, @JackZhangCNCC)
- fixed invalid experience bonus structure in the configuration file
- added config for mobs that should be immune to Bleeding
- updated Russian translation (thanks to @LolsShow and Faster Than Light team)
- fixed bug with Blood Moons not working after 2nd night (reported by @FireKyleA1205)
- fixed bug that sometimes kicks from the game when opening Treasure Bags (reported by @GenericCherrySwitch)
- fixed bug with Skeleton Horse and Zombie Horse not being immune to Bleeding
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ private static void tick( OnClientTicked data ) {
return;
}

if( BloodMoonHelper.isActive() && BloodMoonConfig.TIME.within( level.getDayTime() % Level.TICKS_PER_DAY ) ) {
COLOR_RATIO = ( float )( 2.0 * ( level.getDayTime() - BloodMoonConfig.TIME.from ) / ( BloodMoonConfig.TIME.to - BloodMoonConfig.TIME.from ) - 1.0 );
long relativeTime = level.getDayTime() % Level.TICKS_PER_DAY;
if( BloodMoonHelper.isActive() && BloodMoonConfig.TIME.within( relativeTime ) ) {
COLOR_RATIO = ( float )( 2.0 * ( relativeTime - BloodMoonConfig.TIME.from ) / ( BloodMoonConfig.TIME.to - BloodMoonConfig.TIME.from ) - 1.0 );
COLOR_RATIO = 1.0f - Math.abs( COLOR_RATIO * COLOR_RATIO * COLOR_RATIO );
} else {
COLOR_RATIO = 0.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.majruszlibrary.platform.Side;
import com.majruszsdifficulty.MajruszsDifficulty;
import com.majruszsdifficulty.data.WorldData;
import net.minecraft.world.level.Level;

import java.util.Optional;

public class BloodMoonHelper {
private static BloodMoon BLOOD_MOON = new BloodMoon();
Expand Down Expand Up @@ -42,11 +45,15 @@ public static float getColorRatio() {
return BloodMoonClient.COLOR_RATIO;
}

public static long getRelativeDayTime() {
return Optional.ofNullable( Side.getServer() ).map( server->server.overworld().getDayTime() % Level.TICKS_PER_DAY ).orElse( 0L );
}

public static boolean isActive() {
return BLOOD_MOON.isActive();
}

public static boolean isValidDayTime() {
return BloodMoonConfig.TIME.within( Side.getServer().overworld().getDayTime() );
return BloodMoonConfig.TIME.within( BloodMoonHelper.getRelativeDayTime() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

import com.majruszlibrary.events.OnServerTicked;
import com.majruszlibrary.events.base.Condition;
import com.majruszlibrary.platform.Side;
import com.majruszsdifficulty.bloodmoon.BloodMoonConfig;
import com.majruszsdifficulty.bloodmoon.BloodMoonHelper;
import net.minecraft.world.level.Level;

import java.util.Optional;

public class Trigger {
static {
OnServerTicked.listen( Trigger::start )
.addCondition( data->BloodMoonConfig.IS_ENABLED )
.addCondition( data->Trigger.getTime() == BloodMoonConfig.TIME.from )
.addCondition( data->BloodMoonHelper.getRelativeDayTime() == BloodMoonConfig.TIME.from )
.addCondition( Condition.chance( ()->BloodMoonConfig.NIGHT_TRIGGER_CHANCE ) );

OnServerTicked.listen( Trigger::finish )
.addCondition( data->BloodMoonConfig.IS_ENABLED )
.addCondition( data->!BloodMoonConfig.TIME.within( Trigger.getTime() ) )
.addCondition( data->!BloodMoonHelper.isValidDayTime() )
.addCondition( data->BloodMoonHelper.isActive() );
}

Expand All @@ -29,8 +25,4 @@ private static void start( OnServerTicked data ) {
private static void finish( OnServerTicked data ) {
BloodMoonHelper.stop();
}

private static long getTime() {
return Optional.ofNullable( Side.getServer() ).map( server->server.overworld().getDayTime() % Level.TICKS_PER_DAY ).orElse( 0L );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static boolean isEnabled() {
}

public static boolean canApplyTo( LivingEntity entity ) {
return BleedingConfig.IS_APPLICABLE_TO_ANIMALS && entity instanceof Animal
|| BleedingConfig.IS_APPLICABLE_TO_ILLAGERS && entity instanceof Mob mob && mob.getMobType() == MobType.ILLAGER
return BleedingConfig.IS_APPLICABLE_TO_ANIMALS && entity instanceof Animal && !BleedingConfig.IMMUNE_MOBS.contains( entity.getType() )
|| BleedingConfig.IS_APPLICABLE_TO_ILLAGERS && entity instanceof Mob mob && mob.getMobType() == MobType.ILLAGER && !BleedingConfig.IMMUNE_MOBS.contains( entity.getType() )
|| BleedingConfig.OTHER_APPLICABLE_MOBS.contains( entity.getType() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BleedingConfig {
public static boolean IS_APPLICABLE_TO_ANIMALS = true;
public static boolean IS_APPLICABLE_TO_ILLAGERS = true;
public static List< EntityType< ? > > OTHER_APPLICABLE_MOBS = List.of( EntityType.PLAYER, EntityType.VILLAGER );
public static List< EntityType< ? > > IMMUNE_MOBS = List.of( EntityType.ZOMBIE_HORSE, EntityType.SKELETON_HORSE );
public static GameStageValue< EffectDef > EFFECTS = GameStageValue.of(
DefaultMap.defaultEntry( new EffectDef( ()->null, 0, 24.0f ) ),
DefaultMap.entry( GameStage.EXPERT_ID, new EffectDef( ()->null, 1, 24.0f ) ),
Expand All @@ -32,6 +33,7 @@ public class BleedingConfig {
.define( "is_applicable_to_animals", Reader.bool(), ()->IS_APPLICABLE_TO_ANIMALS, v->IS_APPLICABLE_TO_ANIMALS = v )
.define( "is_applicable_to_pillagers", Reader.bool(), ()->IS_APPLICABLE_TO_ILLAGERS, v->IS_APPLICABLE_TO_ILLAGERS = v )
.define( "other_applicable_mobs", Reader.list( Reader.entityType() ), ()->OTHER_APPLICABLE_MOBS, v->OTHER_APPLICABLE_MOBS = v )
.define( "immune_mobs", Reader.list( Reader.entityType() ), ()->IMMUNE_MOBS, v->IMMUNE_MOBS = v )
.define( "effect", Reader.map( Reader.custom( EffectDef::new ) ), ()->EFFECTS.get(), v->EFFECTS.set( v ) )
.define( "sources", Sources.class );
}
Expand Down
20 changes: 12 additions & 8 deletions common/src/main/java/com/majruszsdifficulty/items/TreasureBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.majruszlibrary.item.ItemHelper;
import com.majruszlibrary.item.LootHelper;
import com.majruszlibrary.platform.Side;
import com.majruszlibrary.time.TimeHelper;
import com.majruszsdifficulty.MajruszsDifficulty;
import com.majruszsdifficulty.treasurebag.events.OnTreasureBagOpened;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -84,14 +85,17 @@ private static void openInHand( OnPlayerInteracted data ) {
}

private static void openInInventory( RightClickAction action, ServerPlayer player ) {
if( !player.containerMenu.isValidSlotIndex( action.containerIdx ) ) {
return;
}

ItemStack itemStack = player.containerMenu.getSlot( action.containerIdx ).getItem();
if( itemStack.getItem() instanceof TreasureBag ) {
TreasureBag.open( itemStack, player );
}
// delayed on purpose to avoid accessing randoms from 'network' thread
TimeHelper.nextTick( d->{
if( !player.containerMenu.isValidSlotIndex( action.containerIdx ) ) {
return;
}

ItemStack itemStack = player.containerMenu.getSlot( action.containerIdx ).getItem();
if( itemStack.getItem() instanceof TreasureBag ) {
TreasureBag.open( itemStack, player );
}
} );
}

private static void open( ItemStack itemStack, Player player ) {
Expand Down
Loading

0 comments on commit 6a8bb11

Please sign in to comment.