Skip to content

Commit

Permalink
Quilt Compatibility Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJoeMama committed Aug 17, 2022
1 parent aaf076e commit ec2af74
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 91 deletions.
20 changes: 14 additions & 6 deletions src/main/java/io/github/llamarama/team/Llamarama.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package io.github.llamarama.team;

import io.github.llamarama.team.common.event.EventHandler;
import io.github.llamarama.team.common.register.*;
import io.github.llamarama.team.common.register.ModBiomeModifications;
import io.github.llamarama.team.common.register.ModBlockEntityTypes;
import io.github.llamarama.team.common.register.ModBlocks;
import io.github.llamarama.team.common.register.ModEntityTypes;
import io.github.llamarama.team.common.register.ModItems;
import io.github.llamarama.team.common.register.ModMemoryModules;
import io.github.llamarama.team.common.register.ModPointOfInterestTypes;
import io.github.llamarama.team.common.register.ModSensorTypes;
import io.github.llamarama.team.common.register.ModSoundEvents;
import io.github.llamarama.team.common.util.IdBuilder;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Llamarama implements ModInitializer {
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;

public class Llamarama implements ModInitializer {
public static final String MOD_ID = "llamarama";
public static final ItemGroup LLAMA_ITEM_GROUP =
FabricItemGroupBuilder.create(IdBuilder.of("llama_item_group"))
Expand All @@ -39,10 +47,10 @@ public void onInitialize() {

// Biome Modifications
ModBiomeModifications.init();
ModBiomeModifications.registerSpawnRestrictions();

// Callback registers.
LootTableEvents.MODIFY.register(EventHandler::lootTableListener);
EventHandler handler = new EventHandler();
LootTableEvents.MODIFY.register(handler);

// Done
Llamarama.getLogger().info("Welcome to the world of Llamas!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.llamarama.team.common.register.ModItems;
import io.github.llamarama.team.common.util.IdBuilder;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.loot.v2.LootTableSource;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootPool;
Expand All @@ -18,11 +19,9 @@
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;


@SuppressWarnings("unused")
public final class EventHandler {

public static void lootTableListener(ResourceManager resourceManager, LootManager lootManager, Identifier id, LootTable.Builder tableBuilder, LootTableSource source) {
public final class EventHandler implements LootTableEvents.Modify {
@Override
public void modifyLootTable(ResourceManager resourceManager, LootManager lootManager, Identifier id, LootTable.Builder tableBuilder, LootTableSource source) {
if (IdBuilder.vanillaOf("entities/llama").equals(id)) {
LootPool.Builder pool =
LootPool.builder()
Expand All @@ -41,5 +40,4 @@ public static void lootTableListener(ResourceManager resourceManager, LootManage
tableBuilder.pool(pool);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package io.github.llamarama.team.common.register;

import io.github.llamarama.team.common.entity.mossyllama.MossyLlamaEntity;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.mixin.object.builder.SpawnRestrictionAccessor;

import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.LlamaEntity;
import net.minecraft.tag.BiomeTags;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.Heightmap;
import net.minecraft.world.biome.BiomeKeys;

public class ModBiomeModifications {

public static void init() {
BiomeModifications.addSpawn(
ctx -> ctx.hasTag(BiomeTags.IS_MOUNTAIN) ||
Expand Down Expand Up @@ -48,37 +40,4 @@ public static void init() {
);
}

public static void registerSpawnRestrictions() {
SpawnRestrictionAccessor.callRegister(
ModEntityTypes.WOOLLY_LLAMA,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
AnimalEntity::isValidNaturalSpawn
);
SpawnRestrictionAccessor.callRegister(
ModEntityTypes.BUMBLE_LLAMA,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
AnimalEntity::isValidNaturalSpawn
);
SpawnRestrictionAccessor.callRegister(
ModEntityTypes.CARAVAN_TRADER,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
MobEntity::canMobSpawn
);
SpawnRestrictionAccessor.callRegister(
ModEntityTypes.MOSSY_LLAMA,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
MossyLlamaEntity::canSpawn
);
SpawnRestrictionAccessor.callRegister(
ModEntityTypes.SANDY_LLAMA,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
LlamaEntity::canMobSpawn
);
}

}
Original file line number Diff line number Diff line change
@@ -1,58 +1,107 @@
package io.github.llamarama.team.common.register;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import io.github.llamarama.team.common.entity.bumbllama.BumbleLlamaEntity;
import io.github.llamarama.team.common.entity.caravantrader.CaravanTraderEntity;
import io.github.llamarama.team.common.entity.mossyllama.MossyLlamaEntity;
import io.github.llamarama.team.common.entity.sandyllama.SandyLlamaEntity;
import io.github.llamarama.team.common.entity.woolyllama.WoollyLlamaEntity;
import io.github.llamarama.team.common.util.IdBuilder;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;

import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import net.minecraft.world.Heightmap;

public final class ModEntityTypes {

private static final Map<String, EntityType<?>> REGISTRY = new HashMap<>();

public static final EntityType<WoollyLlamaEntity> WOOLLY_LLAMA =
register(WoollyLlamaEntity::new, SpawnGroup.CREATURE, 0.9f, 1.87f, false,
WoollyLlamaEntity::createLlamaAttributes, "woolly_llama");
public static final EntityType<BumbleLlamaEntity> BUMBLE_LLAMA =
register(BumbleLlamaEntity::new, SpawnGroup.CREATURE, 0.9f, 1.87f, false,
BumbleLlamaEntity::createLlamaAttributes, "bumble_llama");
public static final EntityType<CaravanTraderEntity> CARAVAN_TRADER =
register(CaravanTraderEntity::new, SpawnGroup.MISC, 0.6f, 1.95f, true,
CaravanTraderEntity::createAttributes, "caravan_trader");
public static final EntityType<MossyLlamaEntity> MOSSY_LLAMA =
register(MossyLlamaEntity::new, SpawnGroup.CREATURE, 0.9f, 1.87f, false,
MossyLlamaEntity::createLlamaAttributes, "mossy_llama");
public static final EntityType<SandyLlamaEntity> SANDY_LLAMA =
register(SandyLlamaEntity::new, SpawnGroup.CREATURE, 0.9f, 1.87f, false,
SandyLlamaEntity::createLlamaAttributes, "sandy_llama");
public static final EntityType<WoollyLlamaEntity> WOOLLY_LLAMA = register(
WoollyLlamaEntity::new,
SpawnGroup.CREATURE,
0.9f, 1.87f, false,
WoollyLlamaEntity::createLlamaAttributes,
new SpawnRestrictionData<>(
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
AnimalEntity::isValidNaturalSpawn
),
"woolly_llama"
);
public static final EntityType<BumbleLlamaEntity> BUMBLE_LLAMA = register(
BumbleLlamaEntity::new,
SpawnGroup.CREATURE,
0.9f, 1.87f, false,
BumbleLlamaEntity::createLlamaAttributes,
new SpawnRestrictionData<>(
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
AnimalEntity::isValidNaturalSpawn
),
"bumble_llama"
);
public static final EntityType<CaravanTraderEntity> CARAVAN_TRADER = register(
CaravanTraderEntity::new,
SpawnGroup.MISC,
0.6f, 1.95f, true,
CaravanTraderEntity::createAttributes,
new SpawnRestrictionData<>(
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
MobEntity::canMobSpawn
),
"caravan_trader"
);
public static final EntityType<MossyLlamaEntity> MOSSY_LLAMA = register(
MossyLlamaEntity::new,
SpawnGroup.CREATURE,
0.9f, 1.87f, false,
MossyLlamaEntity::createLlamaAttributes,
new SpawnRestrictionData<>(
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
MossyLlamaEntity::canSpawn
),
"mossy_llama"
);
public static final EntityType<SandyLlamaEntity> SANDY_LLAMA = register(
SandyLlamaEntity::new,
SpawnGroup.CREATURE,
0.9f, 1.87f, false,
SandyLlamaEntity::createLlamaAttributes,
new SpawnRestrictionData<>(
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
MobEntity::canMobSpawn
),
"sandy_llama"
);

private ModEntityTypes() {
private ModEntityTypes() { }

}

private static <T extends LivingEntity> EntityType<T> register(EntityType.EntityFactory<T> factory,
SpawnGroup group, float width, float height,
boolean fixed,
Supplier<DefaultAttributeContainer.Builder> attributes, String id) {
EntityType<T> type =
FabricEntityTypeBuilder.Living.createLiving()
.spawnGroup(group)
.entityFactory(factory)
.dimensions(new EntityDimensions(width, height, fixed))
.defaultAttributes(attributes)
.build();
private static <T extends MobEntity> EntityType<T> register(EntityType.EntityFactory<T> factory,
SpawnGroup group, float width, float height,
boolean fixed,
Supplier<DefaultAttributeContainer.Builder> attributes,
SpawnRestrictionData<T> spawnRestriction,
String id) {
EntityType<T> type = FabricEntityTypeBuilder.Living.createMob()
.spawnGroup(group)
.entityFactory(factory)
.spawnRestriction(spawnRestriction.location(), spawnRestriction.type(), spawnRestriction.predicate())
.dimensions(new EntityDimensions(width, height, fixed))
.defaultAttributes(attributes)
.build();
REGISTRY.put(id, type);
return type;
}
Expand All @@ -61,4 +110,8 @@ public static void init() {
REGISTRY.forEach((s, entityType) -> Registry.register(Registry.ENTITY_TYPE, IdBuilder.of(s), entityType));
}

public record SpawnRestrictionData<T extends MobEntity>(SpawnRestriction.Location location,
Heightmap.Type type,
SpawnRestriction.SpawnPredicate<T> predicate) { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@Interface(iface = SaddledComponentProvider.class, prefix = "saddle$"),
@Interface(iface = BoostTimeProvider.class, prefix = "boost$")
})
public abstract class MixinLlamaEntity extends AbstractDonkeyEntity implements RangedAttackMob, ItemSteerable {
public abstract class MixinLlamaEntity extends AbstractDonkeyEntity implements RangedAttackMob {

private static TrackedData<Boolean> LLAMARAMA$CARPETED;
private static TrackedData<Integer> LLAMARAMA$BOOST_TIME;
Expand Down Expand Up @@ -71,12 +71,12 @@ public void onInitDataTracker(CallbackInfo ci) {

@Inject(method = "writeCustomDataToNbt", at = @At("RETURN"))
public void onWriteCustomDataToTag(NbtCompound tag, CallbackInfo ci) {
llamarama$saddledComponent.writeNbt(tag);
this.llamarama$saddledComponent.writeNbt(tag);
}

@Inject(method = "readCustomDataFromNbt", at = @At("RETURN"))
public void onReadCustomDataFromTag(NbtCompound tag, CallbackInfo ci) {
llamarama$saddledComponent.readNbt(tag);
this.llamarama$saddledComponent.readNbt(tag);
}

@Inject(method = "getPrimaryPassenger()Lnet/minecraft/entity/LivingEntity;", at = @At("HEAD"), cancellable = true)
Expand All @@ -91,7 +91,7 @@ public void onCanBeControlledByRider(CallbackInfoReturnable<LivingEntity> cir) {

@Override // We have to use override here even though it's not good because we use both this$travel and super$travel
public void travel(Vec3d movementInput) {
this.travel(this, this.llamarama$saddledComponent, movementInput);
((ItemSteerable) this).travel(this, this.llamarama$saddledComponent, movementInput);
}

public boolean impl$consumeOnAStickItem() {
Expand Down

0 comments on commit ec2af74

Please sign in to comment.