Skip to content

Commit

Permalink
Fixed server crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Dec 2, 2023
1 parent 31134fa commit 71a5e17
Show file tree
Hide file tree
Showing 52 changed files with 342 additions and 351 deletions.
Binary file modified common/libs/majrusz-library-common-1.20.1-7.0.0.jar
Binary file not shown.
298 changes: 143 additions & 155 deletions common/src/main/java/com/majruszsdifficulty/MajruszsDifficulty.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public EnderiumBlock() {

public static class Item extends BlockItem {
public Item() {
super( MajruszsDifficulty.Blocks.ENDERIUM_BLOCK.get(), new Properties().stacksTo( 64 ).rarity( Rarity.UNCOMMON ) );
super( MajruszsDifficulty.ENDERIUM_BLOCK.get(), new Properties().stacksTo( 64 ).rarity( Rarity.UNCOMMON ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void tryDropExperience( ServerLevel level, BlockPos position, ItemStac

public static class Item extends BlockItem {
public Item() {
super( MajruszsDifficulty.Blocks.ENDERIUM_SHARD_ORE.get(), new Properties().stacksTo( 64 ) );
super( MajruszsDifficulty.ENDERIUM_SHARD_ORE_BLOCK.get(), new Properties().stacksTo( 64 ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static void destroy( Level level, BlockState blockState, BlockPos blockP

public static class Item extends BlockItem {
public Item() {
super( MajruszsDifficulty.Blocks.FRAGILE_END_STONE.get(), new Properties().stacksTo( 64 ) );
super( MajruszsDifficulty.FRAGILE_END_STONE_BLOCK.get(), new Properties().stacksTo( 64 ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InfernalSponge extends Block {
static {
OnBlockPlaced.listen( InfernalSponge::absorb )
.addCondition( Condition.isLogicalServer() )
.addCondition( data->data.blockState.is( MajruszsDifficulty.Blocks.INFERNAL_SPONGE.get() ) );
.addCondition( data->data.blockState.is( MajruszsDifficulty.INFERNAL_SPONGE_BLOCK.get() ) );
}

public InfernalSponge() {
Expand Down Expand Up @@ -68,13 +68,13 @@ private static void absorb( Level level, BlockPos spongePos ) {
} ) - 1;

if( absorbedBlocks > 0 ) {
level.setBlock( spongePos, MajruszsDifficulty.Blocks.SOAKED_INFERNAL_SPONGE.get().defaultBlockState(), 2 );
level.setBlock( spongePos, MajruszsDifficulty.SOAKED_INFERNAL_SPONGE_BLOCK.get().defaultBlockState(), 2 );
}
}

public static class Item extends BlockItem {
public Item() {
super( MajruszsDifficulty.Blocks.INFERNAL_SPONGE.get(), new Properties().rarity( Rarity.UNCOMMON ).fireResistant() );
super( MajruszsDifficulty.INFERNAL_SPONGE_BLOCK.get(), new Properties().rarity( Rarity.UNCOMMON ).fireResistant() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void tryToSpawnEndermite( Level level, ItemStack itemStack, BlockPos blo

public static class Item extends BlockItem {
public Item() {
super( MajruszsDifficulty.Blocks.INFESTED_END_STONE.get(), new Properties().stacksTo( 64 ) );
super( MajruszsDifficulty.INFESTED_END_STONE_BLOCK.get(), new Properties().stacksTo( 64 ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SoakedInfernalSponge extends Block {
static {
OnBlockPlaced.listen( SoakedInfernalSponge::tryToConvert )
.addCondition( Condition.isLogicalServer() )
.addCondition( data->data.blockState.is( MajruszsDifficulty.Blocks.SOAKED_INFERNAL_SPONGE.get() ) );
.addCondition( data->data.blockState.is( MajruszsDifficulty.SOAKED_INFERNAL_SPONGE_BLOCK.get() ) );
}

public SoakedInfernalSponge() {
Expand Down Expand Up @@ -98,7 +98,7 @@ private static void tryToConvert( Level level, BlockPos blockPos ) {
for( Direction direction : Direction.values() ) {
FluidState fluidState = level.getFluidState( blockPos.relative( direction ) );
if( fluidState.is( Fluids.WATER ) || fluidState.is( Fluids.FLOWING_WATER ) ) {
level.setBlock( blockPos, MajruszsDifficulty.Blocks.INFERNAL_SPONGE.get().defaultBlockState(), 2 );
level.setBlock( blockPos, MajruszsDifficulty.INFERNAL_SPONGE_BLOCK.get().defaultBlockState(), 2 );
SoundEmitter.of( SoundEvents.LAVA_EXTINGUISH )
.position( blockPos.getCenter() )
.emit( level );
Expand All @@ -109,7 +109,7 @@ private static void tryToConvert( Level level, BlockPos blockPos ) {

public static class Item extends BlockItem {
public Item() {
super( MajruszsDifficulty.Blocks.SOAKED_INFERNAL_SPONGE.get(), new Properties().rarity( Rarity.UNCOMMON ).fireResistant() );
super( MajruszsDifficulty.SOAKED_INFERNAL_SPONGE_BLOCK.get(), new Properties().rarity( Rarity.UNCOMMON ).fireResistant() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public class BloodMoon {
.define( "is_active", Reader.bool(), s->s.isActive, ( s, v )->s.isActive = v );
}

public boolean setActive( boolean isActive ) {
return isActive ? this.start() : this.finish();
}

public boolean start() {
if( !this.isActive && BloodMoonHelper.isValidDayTime() && !Events.dispatch( new OnBloodMoonStarted() ).isCancelled() ) {
this.isActive = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BloodMoonHelper {
.define( "blood_moon", Reader.custom( BloodMoon::new ), ()->BLOOD_MOON, v->BLOOD_MOON = v );

Serializables.getStatic( WorldData.Client.class )
.define( "blood_moon", Reader.bool(), ()->BLOOD_MOON.isActive(), v->BLOOD_MOON.setActive( v ) );
.define( "blood_moon", Reader.bool(), ()->BLOOD_MOON.isActive(), v->BLOOD_MOON.isActive = v );
}

public static boolean start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.majruszsdifficulty.data;

import com.majruszlibrary.data.Serializables;

public class WorldData {
static {
Serializables.getStatic( WorldData.class );

Serializables.getStatic( WorldData.Client.class );
}

public static class Client {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static class MobEffectInstance extends net.minecraft.world.effect.MobEffe
public final @Nullable Entity damageSourceEntity;

public MobEffectInstance( int duration, int amplifier, @Nullable LivingEntity attacker ) {
super( MajruszsDifficulty.Effects.BLEEDING.get(), duration, amplifier, false, false, true );
super( MajruszsDifficulty.BLEEDING_EFFECT.get(), duration, amplifier, false, false, true );

this.damageSourceEntity = attacker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public class BleedingImmunity extends MobEffect {
static {
OnEntityEffectCheck.listen( OnEntityEffectCheck::cancelEffect )
.addCondition( data->EffectHelper.has( MajruszsDifficulty.Effects.BLEEDING_IMMUNITY, data.entity ) )
.addCondition( data->data.effect.equals( MajruszsDifficulty.Effects.BLEEDING.get() ) );
.addCondition( data->EffectHelper.has( MajruszsDifficulty.BLEEDING_IMMUNITY_EFFECT, data.entity ) )
.addCondition( data->data.effect.equals( MajruszsDifficulty.BLEEDING_EFFECT.get() ) );
}

public BleedingImmunity() {
Expand All @@ -25,7 +25,7 @@ public void applyEffectTick( LivingEntity entity, int amplifier ) {}

@Override
public void applyInstantenousEffect( @Nullable Entity source, @Nullable Entity indirectSource, LivingEntity entity, int amplifier, double health ) {
entity.removeEffect( MajruszsDifficulty.Effects.BLEEDING.get() );
entity.removeEffect( MajruszsDifficulty.BLEEDING_EFFECT.get() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GlassRegeneration extends MobEffect {
static {
OnEntityDamaged.listen( GlassRegeneration::removeOnHit )
.addCondition( Condition.isLogicalServer() )
.addCondition( data->EffectHelper.has( MajruszsDifficulty.Effects.GLASS_REGENERATION, data.target ) );
.addCondition( data->EffectHelper.has( MajruszsDifficulty.GLASS_REGENERATION_EFFECT, data.target ) );
}

public GlassRegeneration() {
Expand All @@ -49,7 +49,7 @@ public boolean isDurationEffectTick( int duration, int amplifier ) {
}

private static void removeOnHit( OnEntityDamaged data ) {
data.target.removeEffect( MajruszsDifficulty.Effects.GLASS_REGENERATION.get() );
data.target.removeEffect( MajruszsDifficulty.GLASS_REGENERATION_EFFECT.get() );
GLASS_BREAK.position( data.target.position() ).emit( data.getServerLevel() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BleedingAppleProtection {
}

private static void cancelBleeding( OnItemEaten data ) {
data.entity.removeEffect( MajruszsDifficulty.Effects.BLEEDING.get() );
data.entity.removeEffect( MajruszsDifficulty.BLEEDING_EFFECT.get() );
}

private static void addTooltip( OnItemTooltip data ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BleedingArmorProtection {
static {
OnEntityEffectCheck.listen( OnEntityEffectCheck::cancelEffect )
.addCondition( Condition.isLogicalServer() )
.addCondition( data->data.effect.equals( MajruszsDifficulty.Effects.BLEEDING.get() ) )
.addCondition( data->data.effect.equals( MajruszsDifficulty.BLEEDING_EFFECT.get() ) )
.addCondition( data->Random.check( BleedingArmorProtection.calculateCancelChance( data ) ) );

OnBleedingTooltip.listen( BleedingArmorProtection::addTooltip )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BleedingDamage {

OnEntityTicked.listen( BleedingDamage::tick )
.addCondition( Condition.isLogicalServer() )
.addCondition( data->EffectHelper.has( MajruszsDifficulty.Effects.BLEEDING, data.entity ) );
.addCondition( data->EffectHelper.has( MajruszsDifficulty.BLEEDING_EFFECT, data.entity ) );
}

private static void tryToApply( OnEntityDamaged data ) {
Expand All @@ -42,7 +42,7 @@ private static void tryToApply( OnEntityDamaged data ) {
}

private static void tick( OnEntityTicked data ) {
int amplifier = EffectHelper.getAmplifier( MajruszsDifficulty.Effects.BLEEDING, data.entity ).orElse( 0 );
int amplifier = EffectHelper.getAmplifier( MajruszsDifficulty.BLEEDING_EFFECT, data.entity ).orElse( 0 );
int extraDuration = Random.round( 0.3 * ( amplifier + 2 ) * ( 7.26 * EntityHelper.getWalkDistanceDelta( data.entity ) + 1 ) );
int duration = ENTITY_TICKS.getOrDefault( data.entity.getId(), 0 ) + extraDuration;
if( duration > DAMAGE_COOLDOWN ) {
Expand All @@ -57,9 +57,9 @@ private static void dealDamage( LivingEntity entity ) {
Holder< DamageType > damageType = entity.level()
.registryAccess()
.registryOrThrow( net.minecraft.core.registries.Registries.DAMAGE_TYPE )
.getHolderOrThrow( MajruszsDifficulty.DamageSources.BLEEDING );
.getHolderOrThrow( MajruszsDifficulty.BLEEDING_DAMAGE_SOURCE );

if( entity.getEffect( MajruszsDifficulty.Effects.BLEEDING.get() ) instanceof Bleeding.MobEffectInstance effectInstance ) {
if( entity.getEffect( MajruszsDifficulty.BLEEDING_EFFECT.get() ) instanceof Bleeding.MobEffectInstance effectInstance ) {
Vec3 motion = entity.getDeltaMovement();
entity.hurt( new DamageSource( damageType, null, effectInstance.damageSourceEntity ), 1.0f );
entity.setDeltaMovement( motion ); // sets previous motion to avoid any knockback from bleeding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ public class BleedingParticles {
OnEntityTicked.listen( BleedingParticles::emit )
.addCondition( Condition.isLogicalServer() )
.addCondition( Condition.cooldown( 0.15f ) )
.addCondition( data->EffectHelper.has( MajruszsDifficulty.Effects.BLEEDING, data.entity ) );
.addCondition( data->EffectHelper.has( MajruszsDifficulty.BLEEDING_EFFECT, data.entity ) );

OnEntityDied.listen( BleedingParticles::emit )
.addCondition( Condition.isLogicalServer() )
.addCondition( data->EffectHelper.has( MajruszsDifficulty.Effects.BLEEDING, data.target ) );
.addCondition( data->EffectHelper.has( MajruszsDifficulty.BLEEDING_EFFECT, data.target ) );

OnEntityPreDamaged.listen( BleedingParticles::addGuiOverlay )
.priority( Priority.LOWEST )
.addCondition( data->data.source.is( MajruszsDifficulty.DamageSources.BLEEDING ) );
.addCondition( data->data.source.is( MajruszsDifficulty.BLEEDING_DAMAGE_SOURCE ) );
}

private static void emit( OnEntityTicked data ) {
int amplifier = EffectHelper.getAmplifier( MajruszsDifficulty.Effects.BLEEDING, data.entity ).orElse( 0 );
int amplifier = EffectHelper.getAmplifier( MajruszsDifficulty.BLEEDING_EFFECT, data.entity ).orElse( 0 );
float walkDistanceDelta = EntityHelper.getWalkDistanceDelta( data.entity );

ParticleEmitter.of( MajruszsDifficulty.Particles.BLOOD )
ParticleEmitter.of( MajruszsDifficulty.BLOOD_PARTICLE )
.count( Random.round( 0.5 + 0.5 * ( 15.0 + amplifier ) * walkDistanceDelta ) )
.sizeBased( data.entity )
.offset( AnyPos.from( data.entity.getBbWidth(), data.entity.getBbHeight(), data.entity.getBbWidth() ).mul( 0.25, 0.25, 0.25 ).vec3() )
.emit( data.getServerLevel() );
}

private static void emit( OnEntityDied data ) {
ParticleEmitter.of( MajruszsDifficulty.Particles.BLOOD )
ParticleEmitter.of( MajruszsDifficulty.BLOOD_PARTICLE )
.count( 50 )
.sizeBased( data.target )
.offset( AnyPos.from( data.target.getBbWidth(), data.target.getBbHeight(), data.target.getBbWidth() ).mul( 0.25, 0.25, 0.25 ).vec3() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import com.majruszlibrary.events.base.Condition;
import com.majruszlibrary.math.AnyPos;
import com.majruszlibrary.math.Random;
import com.majruszlibrary.modhelper.LazyResource;
import com.majruszlibrary.modhelper.Resource;
import com.majruszlibrary.time.TimeHelper;
import com.majruszsdifficulty.MajruszsDifficulty;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.PackType;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.damagesource.DamageSource;
Expand All @@ -43,7 +42,7 @@
import net.minecraft.world.phys.Vec3;

public class Cerberus extends Monster implements IAnimableEntity {
private static final LazyResource< AnimationsDef > ANIMATIONS = MajruszsDifficulty.HELPER.load( "cerberus_animation", AnimationsDef.class, PackType.SERVER_DATA );
private static final Resource< AnimationsDef > ANIMATIONS = MajruszsDifficulty.HELPER.load( "cerberus_animation", AnimationsDef.class );
private final Animations animations = Animations.create();

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
import com.majruszlibrary.annotation.Dist;
import com.majruszlibrary.annotation.OnlyIn;
import com.majruszlibrary.math.AnyPos;
import com.majruszlibrary.modhelper.LazyResource;
import com.majruszlibrary.modhelper.Resource;
import com.majruszlibrary.platform.Side;
import com.majruszsdifficulty.MajruszsDifficulty;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.Mth;

@OnlyIn( Dist.CLIENT )
public class CerberusModel< Type extends Cerberus > extends HierarchicalModel< Type > {
public static LazyResource< ModelDef > MODEL = MajruszsDifficulty.HELPER.load( "cerberus_model", ModelDef.class, PackType.CLIENT_RESOURCES );
public static Resource< ModelDef > MODEL = MajruszsDifficulty.HELPER.loadClient( "cerberus_model", ModelDef.class );
public final ModelParts modelParts;
public final ModelPart body, necks, neck1, neck3, jawUpper1, jawUpper2, jawUpper3, jawLower1, jawLower2, jawLower3, frontLeg1, frontLeg2, hindLeg1, hindLeg2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import com.majruszlibrary.animations.ModelParts;
import com.majruszlibrary.annotation.Dist;
import com.majruszlibrary.annotation.OnlyIn;
import com.majruszlibrary.modhelper.LazyResource;
import com.majruszlibrary.modhelper.Resource;
import com.majruszsdifficulty.MajruszsDifficulty;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.Mth;

@OnlyIn( Dist.CLIENT )
public class CreeperlingModel< Type extends Creeperling > extends HierarchicalModel< Type > {
public static LazyResource< ModelDef > MODEL = MajruszsDifficulty.HELPER.load( "creeperling_model", ModelDef.class, PackType.CLIENT_RESOURCES );
public static Resource< ModelDef > MODEL = MajruszsDifficulty.HELPER.loadClient( "creeperling_model", ModelDef.class );
public final ModelParts modelParts;
public final ModelPart head, leftBackFoot, leftFrontFoot, rightBackFoot, rightFrontFoot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.majruszlibrary.math.AnyPos;
import com.majruszlibrary.math.Random;
import com.majruszlibrary.math.Range;
import com.majruszlibrary.modhelper.LazyResource;
import com.majruszlibrary.modhelper.Resource;
import com.majruszlibrary.text.TextHelper;
import com.majruszlibrary.time.TimeHelper;
import com.majruszsdifficulty.MajruszsDifficulty;
Expand All @@ -31,7 +31,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.PackType;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -59,7 +58,7 @@
import java.util.function.Function;

public class CursedArmor extends Monster implements IAnimableEntity {
private static final LazyResource< AnimationsDef > ANIMATIONS = MajruszsDifficulty.HELPER.load( "cursed_armor_animation", AnimationsDef.class, PackType.SERVER_DATA );
private static final Resource< AnimationsDef > ANIMATIONS = MajruszsDifficulty.HELPER.load( "cursed_armor_animation", AnimationsDef.class );
private static float ITEM_DROP_CHANCE = 0.2f;
private static float NAME_CHANCE = 0.025f;
private static List< String > NAMES = List.of( "Freshah" );
Expand Down Expand Up @@ -252,7 +251,7 @@ private static LocationDef getRandomLocationDef() {

private static void spawnCursedArmor( OnLootGenerated data ) {
TimeHelper.nextTick( delay->{
CursedArmor cursedArmor = EntityHelper.createSpawner( MajruszsDifficulty.Entities.CURSED_ARMOR, data.getLevel() )
CursedArmor cursedArmor = EntityHelper.createSpawner( MajruszsDifficulty.CURSED_ARMOR_ENTITY, data.getLevel() )
.position( CursedArmor.getSpawnPosition( data ) )
.beforeEvent( entity->{
float yRot = BlockHelper.getState( data.getLevel(), data.origin ).getValue( ChestBlock.FACING ).toYRot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import com.majruszlibrary.animations.ModelParts;
import com.majruszlibrary.annotation.Dist;
import com.majruszlibrary.annotation.OnlyIn;
import com.majruszlibrary.modhelper.LazyResource;
import com.majruszlibrary.modhelper.Resource;
import com.majruszsdifficulty.MajruszsDifficulty;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.server.packs.PackType;

@OnlyIn( Dist.CLIENT )
public class CursedArmorModel< Type extends CursedArmor > extends HumanoidModel< Type > {
public static LazyResource< ModelDef > MODEL = MajruszsDifficulty.HELPER.load( "cursed_armor_model", ModelDef.class, PackType.CLIENT_RESOURCES );
public static Resource< ModelDef > MODEL = MajruszsDifficulty.HELPER.loadClient( "cursed_armor_model", ModelDef.class );
public final ModelParts modelParts;

public CursedArmorModel( ModelPart modelPart ) {
Expand Down
Loading

0 comments on commit 71a5e17

Please sign in to comment.