Skip to content

Commit

Permalink
Backported 1.19.3 changes to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Jan 23, 2023
1 parent 518f8f8 commit da1cca4
Show file tree
Hide file tree
Showing 45 changed files with 96 additions and 279 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ apply plugin: 'org.spongepowered.mixin'

version = '3.1.0'
group = 'com.mlib' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'majrusz-library-1.19.2'
archivesBaseName = 'majrusz-library-1.18.2'

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
compileJava {
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
}

minecraft {
mappings channel: 'official', version: '1.19.2'
mappings channel: 'official', version: '1.18.2'

accessTransformer = file( 'src/main/resources/META-INF/accesstransformer.cfg' ) // Currently, this location cannot be changed from the default.

Expand Down Expand Up @@ -91,7 +91,7 @@ mixin {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.19.2-43.2.0'
minecraft 'net.minecraftforge:forge:1.18.2-40.2.0'

annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/com/mlib/NetworkHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package com.mlib;

import com.mlib.mixininterfaces.IMixinEntity;
import com.mlib.network.NetworkMessage;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;

Expand All @@ -19,31 +10,5 @@ public class NetworkHandler {

static void register( final FMLCommonSetupEvent event ) {
CHANNEL = NetworkRegistry.newSimpleChannel( Registries.getLocation( "main" ), ()->PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals );
CHANNEL.registerMessage( 0, GlowEntityMessage.class, GlowEntityMessage::encode, GlowEntityMessage::new, GlowEntityMessage::handle );
}

public static class GlowEntityMessage extends NetworkMessage {
final int entityId;
final int ticks;

public GlowEntityMessage( Entity entity, int ticks ) {
this.entityId = this.write( entity );
this.ticks = this.write( ticks );
}

public GlowEntityMessage( FriendlyByteBuf buffer ) {
this.entityId = this.readEntity( buffer );
this.ticks = this.readInt( buffer );
}

@Override
@OnlyIn( Dist.CLIENT )
public void receiveMessage( NetworkEvent.Context context ) {
Level level = Minecraft.getInstance().level;
if( level == null )
return;

IMixinEntity.addGlowTicks( level.getEntity( this.entityId ), this.ticks );
}
}
}
7 changes: 3 additions & 4 deletions src/main/java/com/mlib/Random.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
import com.mlib.math.VectorHelper;
import com.mojang.math.Vector3f;
import net.minecraft.core.Vec3i;
import net.minecraft.util.RandomSource;
import net.minecraft.world.phys.Vec3;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class Random {
static final RandomSource CLIENT = RandomSource.create();
static final RandomSource SERVER = RandomSource.create();
static final java.util.Random CLIENT = new java.util.Random();
static final java.util.Random SERVER = new java.util.Random();

/**
Returns random source which depends on current thread, to make sure all functions are
thread safe and can be accessed on both server and client at the same time.
*/
public static RandomSource getThreadSafe() {
public static java.util.Random getThreadSafe() {
return Utility.isServerSide() ? SERVER : CLIENT;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/mlib/Registries.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.serialization.Codec;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand All @@ -20,14 +21,14 @@

public class Registries {
static final RegistryHelper HELPER = new RegistryHelper( MajruszLibrary.MOD_ID );
static final DeferredRegister< Codec< ? extends IGlobalLootModifier > > LOOT_MODIFIERS = HELPER.create( ForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS );
static final DeferredRegister< GlobalLootModifierSerializer< ? > > LOOT_MODIFIERS = HELPER.create( ForgeRegistries.Keys.LOOT_MODIFIER_SERIALIZERS );
static final List< Command > COMMANDS;
static final List< GameModifier > GAME_MODIFIERS;

static {
GameModifier.addNewGroup( CONFIG_HANDLER, GameModifier.DEFAULT_KEY );

LOOT_MODIFIERS.register( "any_situation", AnyModification.CODEC );
LOOT_MODIFIERS.register( "any_situation", AnyModification.Serializer::new );

AnnotationHandler annotationHandler = new AnnotationHandler( MajruszLibrary.MOD_ID );
COMMANDS = annotationHandler.getInstances( Command.class );
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mlib/animations/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public static void addPosition( Vector3f value, ModelPart... modelParts ) {
}

public static void applyScale( float value, ModelPart... modelParts ) {
for( ModelPart modelPart : modelParts ) {
/*for( ModelPart modelPart : modelParts ) {
modelPart.xScale = value;
modelPart.yScale = value;
modelPart.zScale = value;
}
}*/
}

public Animation< Type > add( float duration, Frame< Type > frame ) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mlib/client/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ClientHelper {
protected static int leftAltLastAction = 0;

@SubscribeEvent
public static void onKeyInput( InputEvent.Key event ) {
public static void onKeyInput( InputEvent.KeyInputEvent event ) {
switch( event.getKey() ) {
case 340 -> shiftLastAction = event.getAction();
case 341 -> ctrlLastAction = event.getAction();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/mlib/commands/CommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.server.command.EnumArgument;

import java.util.ArrayList;
Expand Down Expand Up @@ -123,7 +124,7 @@ public CommandBuilder hasPermission( int requiredLevel ) {
}

public CommandBuilder isPlayer() {
return this.add( CommandSourceStack::isPlayer );
return this.add( ( CommandSourceStack stack )->stack.getEntity() instanceof Player );
}

public CommandBuilder isDevelopmentBuild() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/mlib/config/StringConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mlib.config;

import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.*;
import net.minecraftforge.common.ForgeConfigSpec;

public class StringConfig extends ValueConfig< String > {
Expand All @@ -16,10 +16,10 @@ public void build( ForgeConfigSpec.Builder builder ) {
}

public Component asLiteral() {
return Component.literal( this.getOrDefault() );
return new TextComponent( this.getOrDefault() );
}

public Component asTranslatable( Object... params ) {
return Component.translatable( this.getOrDefault(), params );
return new TranslatableComponent( this.getOrDefault(), params );
}
}
1 change: 0 additions & 1 deletion src/main/java/com/mlib/effects/SoundHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class SoundHandler {
public static final SoundHandler ENCHANT = new SoundHandler( SoundEvents.ENCHANTMENT_TABLE_USE, SoundSource.PLAYERS );
public static final SoundHandler ENDERMAN_TELEPORT = new SoundHandler( SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS );
public static final SoundHandler FIRE_EXTINGUISH = new SoundHandler( SoundEvents.GENERIC_EXTINGUISH_FIRE, SoundSource.AMBIENT );
public static final SoundHandler HEARTBEAT = new SoundHandler( SoundEvents.WARDEN_HEARTBEAT, SoundSource.PLAYERS );
public static final SoundHandler ITEM_BREAK = new SoundHandler( SoundEvents.ITEM_BREAK, SoundSource.PLAYERS );
public static final SoundHandler ITEM_PICKUP = new SoundHandler( SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS );
public static final SoundHandler SMELT = new SoundHandler( SoundEvents.FIRECHARGE_USE, SoundSource.AMBIENT );
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mlib/enchantments/CustomEnchantment.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public CustomEnchantment maxLevelCost( CostFormula formula ) {
}

public int getEnchantmentLevel( ItemStack itemStack ) {
return itemStack.getEnchantmentLevel( this );
return EnchantmentHelper.getItemEnchantmentLevel( this, itemStack );
}

public int getEnchantmentLevel( LivingEntity entity ) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/mlib/entities/EntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,4 @@ public static < EntityType extends Entity > List< EntityType > getEntitiesInSphe
) {
return getEntitiesInSphere( entityClass, level, entity.position(), radius, extraPredicate );
}

public static void sendExtraClientGlowTicks( ServerPlayer player, Entity target, int ticks ) {
NetworkHandler.CHANNEL.send( PacketDistributor.PLAYER.with( ()->player ), new NetworkHandler.GlowEntityMessage( target, ticks ) );
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/mlib/events/ExplosionSizeEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.level.ExplosionEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -30,7 +30,7 @@ public ExplosionSizeEvent( Level level, Explosion explosion ) {

@SubscribeEvent
public static void onExplosion( ExplosionEvent.Start explosionEvent ) {
Level level = explosionEvent.getLevel();
Level level = explosionEvent.getWorld();
Explosion explosion = explosionEvent.getExplosion();

ExplosionSizeEvent event = new ExplosionSizeEvent( level, explosion );
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/mlib/features/AnyModification.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
package com.mlib.features;

import com.google.common.base.Suppliers;
import com.google.gson.JsonObject;
import com.mlib.events.AnyLootModificationEvent;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.LootModifier;

import javax.annotation.Nonnull;
import java.util.function.Supplier;
import java.util.List;

/** Loot modifier for all situations to handle . */
public class AnyModification extends LootModifier {
public static final Supplier< Codec< AnyModification > > CODEC = Suppliers.memoize( ()->RecordCodecBuilder.create( inst->codecStart( inst ).apply( inst, AnyModification::new ) ) );

public AnyModification( LootItemCondition[] conditionsIn ) {
super( conditionsIn );
}

@Nonnull
@Override
public ObjectArrayList< ItemStack > doApply( ObjectArrayList< ItemStack > generatedLoot, LootContext context ) {
public List< ItemStack > doApply( List< ItemStack > generatedLoot, LootContext context ) {
MinecraftForge.EVENT_BUS.post( new AnyLootModificationEvent( generatedLoot, context ) );
return generatedLoot;
}

@Override
public Codec< ? extends IGlobalLootModifier > codec() {
return CODEC.get();
public static class Serializer extends GlobalLootModifierSerializer< AnyModification > {
@Override
public AnyModification read( ResourceLocation name, JsonObject object, LootItemCondition[] conditions ) {
return new AnyModification( conditions );
}

@Override
public JsonObject write( AnyModification instance ) {
return makeConditions( instance.conditions );
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/mlib/features/FishingLootIncreaser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.mlib.gamemodifiers.parameters.Priority;
import com.mlib.math.VectorHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.*;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -92,15 +92,15 @@ private List< FishedItem > buildFishedItemList( OnItemFished.Data data, List< It
}

private MutableComponent buildMessage( List< FishedItem > fishedItems ) {
MutableComponent message = Component.literal( "(" ).withStyle( ChatFormatting.WHITE );
MutableComponent message = new TextComponent( "(" ).withStyle( ChatFormatting.WHITE );
for( int idx = 0; idx < fishedItems.size(); ++idx ) {
if( idx > 0 ) {
message.append( ", " );
}
message.append( fishedItems.get( idx ).build() );
}

return message.append( Component.literal( ")" ) );
return message.append( new TextComponent( ")" ) );
}

private static class FishedItem {
Expand All @@ -122,7 +122,7 @@ public MutableComponent build() {
.getName( this.itemStack )
.copy()
.withStyle( this.itemFormatting )
.append( Component.literal( this.count > 1 ? String.format( " x%d", this.count ) : "" ).withStyle( this.countFormatting ) );
.append( new TextComponent( this.count > 1 ? String.format( " x%d", this.count ) : "" ).withStyle( this.countFormatting ) );
}

public void increase( ItemStack itemStack, boolean isExtra ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class Data extends ContextData.Event< PlayerEvent.BreakSpeed > {

public Data( PlayerEvent.BreakSpeed event ) {
super( event.getEntity(), event );
this.player = event.getEntity();
this.player = event.getPlayer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Data( LivingHurtEvent event ) {
super( event.getEntity(), event );
this.source = event.getSource();
this.attacker = Utility.castIfPossible( LivingEntity.class, source.getEntity() );
this.target = event.getEntity();
this.target = event.getEntityLiving();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/mlib/gamemodifiers/contexts/OnDeath.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Data( LivingDeathEvent event ) {
super( event.getEntity(), event );
this.source = event.getSource();
this.attacker = Utility.castIfPossible( LivingEntity.class, source.getEntity() );
this.target = event.getEntity();
this.target = event.getEntityLiving();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class Data extends ContextData.Event< PlayerEvent.PlayerChangedDim

public Data( PlayerEvent.PlayerChangedDimensionEvent event ) {
super( event.getEntity(), event );
this.entity = event.getEntity();
this.entity = event.getEntityLiving();
this.from = event.getFrom();
this.to = event.getTo();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mlib.gamemodifiers.Contexts;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraftforge.event.entity.living.MobEffectEvent;
import net.minecraftforge.event.entity.living.PotionEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -23,18 +23,18 @@ public Context( Consumer< Data > consumer ) {
}

@SubscribeEvent
public static void onEffectApplicable( MobEffectEvent.Applicable event ) {
public static void onEffectApplicable( PotionEvent.PotionApplicableEvent event ) {
CONTEXTS.accept( new Data( event ) );
}
}

public static class Data extends ContextData.Event< MobEffectEvent.Applicable > {
public static class Data extends ContextData.Event< PotionEvent.PotionApplicableEvent > {
public final MobEffectInstance effectInstance;
public final MobEffect effect;

public Data( MobEffectEvent.Applicable event ) {
public Data( PotionEvent.PotionApplicableEvent event ) {
super( event.getEntity(), event );
this.effectInstance = event.getEffectInstance();
this.effectInstance = event.getPotionEffect();
this.effect = this.effectInstance.getEffect();
}
}
Expand Down
Loading

0 comments on commit da1cca4

Please sign in to comment.