Skip to content

Commit

Permalink
Merge pull request #6 from OffsetMods538/4-update-to-121
Browse files Browse the repository at this point in the history
Update to 1.21

Ready or not, here I come!
  • Loading branch information
OffsetMonkey538 authored Dec 15, 2024
2 parents 6c8b8fb + 3c075b4 commit e9cdad6
Show file tree
Hide file tree
Showing 31 changed files with 751 additions and 355 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ processResources {
final Map properties = Map<String, String>.of(
"modVersion", project.mod_version,
"supportedMinecraftVersions", project.supported_minecraft_versions,
"fapi_version", project.fapi_version,
"monkeylib538_version", project.monkeylib538_version
)

Expand Down
13 changes: 7 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ org.gradle.parallel = true

# Fabric
# Check at https://fabricmc.net/develop
minecraft_version = 1.20.1
minecraft_version = 1.21.1

# These should be automatically updated, unless the environment
# variable "DISABLE_PROPERTIES_UPDATE" is set.
fapi_version = 0.92.2+1.20.1
yarn_version = 1.20.1+build.10
fapi_version = 0.110.0+1.21.1
yarn_version = 1.21.1+build.3
loader_version = 0.16.9

# Dependencies
## DevAuth, check at https://github.com/DJtheRedstoner/DevAuth
devauth_version = 1.2.1

# MonkeyLib538, check at https://github.com/OffsetMods538/MonkeyLib538
monkeylib538_version = 2.0.2+1.20.1
monkeylib538_version = 2.0.2+1.21

# EMI, check at https://github.com/emilyploszaj/emi/releases
emi_version = 1.0.22+1.20.1
emi_version = 1.1.18+1.21.1

# Mod Properties
mod_version = 1.0.0
supported_minecraft_versions = ~1.20
supported_minecraft_versions = ~1.21
# TODO: set supported version correctly ^^
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.render.debug.DebugRenderer;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.entity.EntityType;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.math.ColorHelper;
import top.offsetmonkey538.compactmobfarms.block.ModBlocks;
import top.offsetmonkey538.compactmobfarms.block.entity.ModBlockEntityTypes;
import top.offsetmonkey538.compactmobfarms.client.gui.screen.ingame.CompactMobFarmScreen;
Expand Down Expand Up @@ -41,87 +46,79 @@ public void onInitializeClient() {

if (spawnEgg == null) return -1;

return spawnEgg.getColor(tintIndex);
return ColorHelper.Argb.fullAlpha(spawnEgg.getColor(tintIndex));
}, ModItems.FILLED_SAMPLE_TAKER);

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_ENTITY_CHANGED, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;
ClientPlayNetworking.registerGlobalReceiver(ModPackets.GuiEntityChanged.ID, (payload, context) -> {
// IntelliJ thinks I should run '.close()' on the MinecraftClient and close the game as it inherits
// from AutoCloseable. Mr. IntelliJ IDEA is totally right.
// noinspection resource
if (!(context.client().currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != payload.syncId()) return;

EntityType<?> livingEntityType = buf.readRegistryValue(Registries.ENTITY_TYPE);

if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;

screen.setEntity(livingEntityType);
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_ENTITY_REMOVED, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;

screen.clearEntity();
screen.setEntity(payload.newEntity().orElse(null));
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GuiHealthChanged.ID, (payload, context) -> {
// IntelliJ thinks I should run '.close()' on the MinecraftClient and close the game as it inherits
// from AutoCloseable. Mr. IntelliJ IDEA is totally right.
// noinspection resource
if (!(context.client().currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != payload.syncId()) return;

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_HEALTH_RESET, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;

screen.resetEntityHealth();
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_HEALTH_CHANGED, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;

float newHealth = buf.readFloat();

if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;

screen.setEntityHealth(newHealth);
if (payload.newHealth().isEmpty()) screen.resetEntityHealth();
else screen.setEntityHealth(payload.newHealth().get());
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_MAX_HEALTH_CHANGED, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;

float newMaxHealth = buf.readFloat();

if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;
ClientPlayNetworking.registerGlobalReceiver(ModPackets.GuiMaxHealthChanged.ID, (payload, context) -> {
// IntelliJ thinks I should run '.close()' on the MinecraftClient and close the game as it inherits
// from AutoCloseable. Mr. IntelliJ IDEA is totally right.
// noinspection resource
if (!(context.client().currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != payload.syncId()) return;

screen.setMaxEntityHealth(newMaxHealth);
screen.setMaxEntityHealth(payload.newMaxHealth());
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_UPDATE_ATTACK_SPEED, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;

float newAttackSpeed = buf.readFloat();

if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;
ClientPlayNetworking.registerGlobalReceiver(ModPackets.GuiAttackSpeedChanged.ID, (payload, context) -> {
// IntelliJ thinks I should run '.close()' on the MinecraftClient and close the game as it inherits
// from AutoCloseable. Mr. IntelliJ IDEA is totally right.
// noinspection resource
if (!(context.client().currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != payload.syncId()) return;

screen.setAttackSpeed(newAttackSpeed);
screen.setAttackSpeed(payload.newAttackSpeed());
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_UPDATE_ATTACK_DAMAGE, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;
ClientPlayNetworking.registerGlobalReceiver(ModPackets.GuiAttackDamageChanged.ID, (payload, context) -> {
// IntelliJ thinks I should run '.close()' on the MinecraftClient and close the game as it inherits
// from AutoCloseable. Mr. IntelliJ IDEA is totally right.
// noinspection resource
if (!(context.client().currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != payload.syncId()) return;

float newAttackDamage = buf.readFloat();

if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;

screen.setAttackDamage(newAttackDamage);
screen.setAttackDamage(payload.newAttackDamage());
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.GUI_DISPLAY_PROBLEM_MESSAGE, (client, handler, buf, responseSender) -> {
if (!(client.currentScreen instanceof CompactMobFarmScreen screen)) return;

Text problemMessage = buf.readText();
ClientPlayNetworking.registerGlobalReceiver(ModPackets.GuiDisplayProblemMessage.ID, (payload, context) -> {
// IntelliJ thinks I should run '.close()' on the MinecraftClient and close the game as it inherits
// from AutoCloseable. Mr. IntelliJ IDEA is totally right.
// noinspection resource
if (!(context.client().currentScreen instanceof CompactMobFarmScreen screen)) return;
if (screen.getScreenHandler().syncId != payload.syncId()) return;

if (screen.getScreenHandler().syncId != buf.readUnsignedByte()) return;

screen.displayProblemMessage(problemMessage);
screen.displayProblemMessage(payload.problemMessage());
});

ClientPlayNetworking.registerGlobalReceiver(ModPackets.UPDATE_ENTITY_TIER_LIST, (client, handler, buf, responseSender) -> {
ClientPlayNetworking.registerGlobalReceiver(ModPackets.EntityTierListChanged.ID, (payload, context) -> {
EntityTiers.INSTANCE.clear();
EntityTiers.INSTANCE.fromUpdatePacket(buf);

EntityTiers.INSTANCE.UNSUPPORTED = payload.unsupported();
EntityTiers.INSTANCE.TIER_0 = payload.tier0();
EntityTiers.INSTANCE.TIER_1 = payload.tier1();
EntityTiers.INSTANCE.TIER_2 = payload.tier2();
EntityTiers.INSTANCE.TIER_3 = payload.tier3();
EntityTiers.INSTANCE.TIER_4 = payload.tier4();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public void register(EmiRegistry registry) {
));
}

registry.setDefaultComparison(ModItems.FILLED_SAMPLE_TAKER, Comparison.compareNbt());
registry.setDefaultComparison(ModItems.FILLED_SAMPLE_TAKER, Comparison.compareComponents());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static void renderEntity(DrawContext context, LivingEntity entity, int x,

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
renderBackground(context);
renderBackground(context, mouseX, mouseY, delta);

super.render(context, mouseX, mouseY, delta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.loot.v3.LootTableEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
Expand All @@ -15,19 +15,22 @@
import net.minecraft.loot.function.SetCountLootFunction;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.offsetmonkey538.compactmobfarms.block.ModBlocks;
import top.offsetmonkey538.compactmobfarms.block.entity.ModBlockEntityTypes;
import top.offsetmonkey538.compactmobfarms.component.ModComponents;
import top.offsetmonkey538.compactmobfarms.config.EntityTierResourceReloadListener;
import top.offsetmonkey538.compactmobfarms.config.EntityTiers;
import top.offsetmonkey538.compactmobfarms.item.ModItems;
import top.offsetmonkey538.compactmobfarms.item.group.ModItemGroups;
import top.offsetmonkey538.compactmobfarms.network.ModPackets;
import top.offsetmonkey538.compactmobfarms.recipe.ModRecipes;
import top.offsetmonkey538.compactmobfarms.screen.ModScreenHandlers;
import top.offsetmonkey538.monkeylib538.utils.EnchantmentUtils;
import top.offsetmonkey538.monkeylib538.utils.IdentifierUtils;

public class CompactMobFarms implements ModInitializer {
Expand All @@ -37,34 +40,33 @@ public class CompactMobFarms implements ModInitializer {
@Override
public void onInitialize() {
ModBlocks.register();
ModComponents.register();
ModItems.register();
ModItemGroups.register();
ModBlockEntityTypes.register();
ModScreenHandlers.register();
ModRecipes.register();
ModPackets.register();

//noinspection UnstableApiUsage
ItemStorage.SIDED.registerForBlockEntity((block, direction) -> block.getDropInventory(), ModBlockEntityTypes.COMPACT_MOB_FARM);
ItemStorage.SIDED.registerForBlockEntity((block, direction) -> block.getDropInventory(), ModBlockEntityTypes.COMPACT_MOB_FARM);

LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
if (!Blocks.SPAWNER.getLootTableId().equals(id) || !source.isBuiltin()) return;
LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> {
if (Blocks.SPAWNER.getLootTableKey() != key || !source.isBuiltin()) return;

LootPool.Builder pool = LootPool.builder()
.with(ItemEntry.builder(ModItems.SPAWNER_SHARD))
.apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(6, 8)))
.apply(ApplyBonusLootFunction.uniformBonusCount(Enchantments.FORTUNE, 5));
.apply(ApplyBonusLootFunction.uniformBonusCount(registries.createRegistryLookup().getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.FORTUNE), 5));

tableBuilder.pool(pool);
});

ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new EntityTierResourceReloadListener());

ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> {
final PacketByteBuf buf = PacketByteBufs.create();

EntityTiers.INSTANCE.toUpdatePacket(buf);

ServerPlayNetworking.send(player, ModPackets.UPDATE_ENTITY_TIER_LIST, buf);
ServerPlayNetworking.send(player, new ModPackets.EntityTierListChanged(
EntityTiers.INSTANCE
));
});
}

Expand Down
Loading

0 comments on commit e9cdad6

Please sign in to comment.