Skip to content

Commit

Permalink
Initial 1.20.6 port
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed May 5, 2024
1 parent 3b98e3e commit 130e0c5
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 62 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id("eclipse")
id("idea")
id("maven-publish")
id("net.neoforged.gradle.userdev") version "7.0.80"
id("net.neoforged.gradle.userdev") version "7.0.109"
}

val minecraft_version: String by project
Expand All @@ -28,8 +28,8 @@ base {
archivesName.set("Regilite")
}

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
// Mojang ships Java 21 to end users in 1.20.5+, so your mod should target Java 21.
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))

runs {
configureEach {
Expand Down Expand Up @@ -105,7 +105,7 @@ tasks.withType<ProcessResources>().configureEach {
)
inputs.properties(replaceProperties)

filesMatching(listOf("META-INF/mods.toml", "pack.mcmeta")) {
filesMatching(listOf("META-INF/neoforge.mods.toml", "pack.mcmeta")) {
expand(replaceProperties)
expand(mutableMapOf("project" to project))
}
Expand Down
13 changes: 8 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ org.gradle.daemon=false
org.gradle.debug=false

## Environment Properties
minecraft_version=1.20.4
minecraft_version_range=[1.20.4,1.21)
neo_version=20.4.160-beta
neo_version_range=[20.4,)
loader_version_range=[1,)
minecraft_version=1.20.6
minecraft_version_range=[1.20.6,1.21)
neo_version=20.6.40-beta
neo_version_range=[20.6,)
loader_version_range=[1,)

neogradle.subsystems.parchment.minecraftVersion=1.20.6
neogradle.subsystems.parchment.mappingsVersion=2024.05.01
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun May 05 14:56:15 BST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.enderio.regilite.holder.RegiliteBlock;
import com.enderio.regilite.registry.BlockRegistry;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -45,22 +47,22 @@ protected void generate() {

//TODO why these 2 methods, can we join them?
@Override
public void generate(BiConsumer<ResourceLocation, LootTable.Builder> p_249322_) {
public void generate(HolderLookup.Provider pRegistries, BiConsumer<ResourceKey<LootTable>, LootTable.Builder> pGenerator) {
this.generate();
Set<ResourceLocation> set = new HashSet<>();
Set<ResourceKey<LootTable>> set = new HashSet<>();

for(DeferredHolder<Block, ? extends Block> block : registered) {
if (block.get().isEnabled(this.enabledFeatures)) {
ResourceLocation resourcelocation = block.get().getLootTable();
if (resourcelocation != BuiltInLootTables.EMPTY && set.add(resourcelocation)) {
LootTable.Builder loottable$builder = this.map.remove(resourcelocation);
var lootTableResourceKey = block.get().getLootTable();
if (lootTableResourceKey != BuiltInLootTables.EMPTY && set.add(lootTableResourceKey)) {
LootTable.Builder loottable$builder = this.map.remove(lootTableResourceKey);
if (loottable$builder == null) {
throw new IllegalStateException(
String.format(Locale.ROOT, "Missing loottable '%s' for '%s'", resourcelocation, BuiltInRegistries.BLOCK.getKey(block.get()))
String.format(Locale.ROOT, "Missing loottable '%s' for '%s'", lootTableResourceKey, BuiltInRegistries.BLOCK.getKey(block.get()))
);
}

p_249322_.accept(resourcelocation, loottable$builder);
pGenerator.accept(lootTableResourceKey, loottable$builder);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ public String getName() {
void onGatherData(GatherDataEvent event) {
PackOutput packOutput = event.getGenerator().getPackOutput();
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider();
CompletableFuture<HolderLookup.Provider> registries = event.getLookupProvider();

RegiliteLangProvider enUs = new RegiliteLangProvider(packOutput, this.modid, "en_us");
enUs.add(this.langEntries);
this.subProviders.add(enUs);

this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.BLOCK, b -> b.builtInRegistryHolder().key(), lookupProvider, modid, existingFileHelper, regilite.getBlock()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.ITEM, b -> b.builtInRegistryHolder().key(), lookupProvider, modid, existingFileHelper, regilite.getItems()));
this.subProviders.add(new RegiliteTagProvider.FluidTagProvider(packOutput, Registries.FLUID, b -> b.builtInRegistryHolder().key(), lookupProvider, modid, existingFileHelper, regilite.getFluids()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.BLOCK_ENTITY_TYPE, b -> b.builtInRegistryHolder().key(), lookupProvider, modid, existingFileHelper, regilite.getBlockEntities()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.ENTITY_TYPE, b -> b.builtInRegistryHolder().key(), lookupProvider, modid, existingFileHelper, regilite.getEntities()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.BLOCK, b -> b.builtInRegistryHolder().key(), registries, modid, existingFileHelper, regilite.getBlock()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.ITEM, b -> b.builtInRegistryHolder().key(), registries, modid, existingFileHelper, regilite.getItems()));
this.subProviders.add(new RegiliteTagProvider.FluidTagProvider(packOutput, Registries.FLUID, b -> b.builtInRegistryHolder().key(), registries, modid, existingFileHelper, regilite.getFluids()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.BLOCK_ENTITY_TYPE, b -> b.builtInRegistryHolder().key(), registries, modid, existingFileHelper, regilite.getBlockEntities()));
this.subProviders.add(new RegiliteTagProvider<>(packOutput, Registries.ENTITY_TYPE, b -> b.builtInRegistryHolder().key(), registries, modid, existingFileHelper, regilite.getEntities()));

this.subProviders.add(new RegiliteBlockStateProvider(packOutput, modid, existingFileHelper, regilite.getBlock()));
this.subProviders.add(new LootTableProvider(packOutput, Collections.emptySet(), List.of(new LootTableProvider.SubProviderEntry(() -> new RegiliteBlockLootProvider(Set.of(), regilite.getBlock()), LootContextParamSets.BLOCK))));
this.subProviders.add(new LootTableProvider(packOutput, Collections.emptySet(),
List.of(new LootTableProvider.SubProviderEntry(() -> new RegiliteBlockLootProvider(Set.of(), regilite.getBlock()), LootContextParamSets.BLOCK)), registries));

this.subProviders.add(new RegiliteItemModelProvider(packOutput, modid, existingFileHelper, regilite.getItems()));
event.getGenerator().addProvider(true, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ResourceLocation itemTexture(ItemLike item) {
public ItemModelBuilder bucketItem(BucketItem item) {
return withExistingParent(BuiltInRegistries.ITEM.getKey(item).toString(), new ResourceLocation(NeoForgeVersion.MOD_ID, "item/bucket"))
.customLoader(DynamicFluidContainerModelBuilder::begin)
.fluid(item.getFluid())
.fluid(item.content)
.end();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import com.enderio.regilite.Regilite;
import com.enderio.regilite.holder.RegiliteBlockEntity;
import com.enderio.regilite.registry.BlockEntityRegistry;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.common.util.NonNullFunction;
import net.neoforged.neoforge.registries.DeferredHolder;

import java.util.function.Function;
import java.util.function.Supplier;

public class BlockEntityRendererEvents {
Expand All @@ -27,7 +26,7 @@ private <T extends BlockEntity> void registerGenericBER(EntityRenderersEvent.Reg
for (DeferredHolder<BlockEntityType<?>, ? extends BlockEntityType<?>> be : regilite.getBlockEntities()) {
//noinspection rawtypes
if (be instanceof RegiliteBlockEntity regiliteBlockEntity) {
Supplier<NonNullFunction<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> renderer = regiliteBlockEntity.getRenderer();
Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> renderer = regiliteBlockEntity.getRenderer();
if (renderer != null) {
var blockEntityType = (BlockEntityType<T>)be.get();
event.registerBlockEntityRenderer(blockEntityType, (c) -> renderer.get().apply(c));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import com.enderio.regilite.Regilite;
import com.enderio.regilite.holder.RegiliteEntity;
import com.enderio.regilite.registry.EntityRegistry;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.common.util.NonNullFunction;
import net.neoforged.neoforge.registries.DeferredHolder;

import java.util.function.Function;
import java.util.function.Supplier;

public class EntityRendererEvents {
Expand All @@ -27,7 +26,7 @@ private <T extends Entity> void registerGenericER(EntityRenderersEvent.RegisterR
for (DeferredHolder<EntityType<?>, ? extends EntityType<?>> e : regilite.getEntities()) {
//noinspection rawtypes
if (e instanceof RegiliteEntity regiliteEntity) {
Supplier<NonNullFunction<EntityRendererProvider.Context, EntityRenderer<? super T>>> renderer = regiliteEntity.getRenderer();
Supplier<Function<EntityRendererProvider.Context, EntityRenderer<? super T>>> renderer = regiliteEntity.getRenderer();
if (renderer != null) {
var entityType = (EntityType<T>)e.get();
event.registerEntityRenderer(entityType, (c) -> renderer.get().apply(c));
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/enderio/regilite/events/ScreenEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.registries.DeferredHolder;

public class ScreenEvents {
Expand All @@ -18,20 +19,19 @@ public ScreenEvents(Regilite regilite) {
this.regilite = regilite;
}

public <T extends AbstractContainerMenu> void genericScreenEvent(FMLClientSetupEvent event) {
public <T extends AbstractContainerMenu> void genericScreenEvent(RegisterMenuScreensEvent event) {
for (DeferredHolder<MenuType<?>, ? extends MenuType<?>> menu : regilite.getMenus()) {
if (menu instanceof RegiliteMenu) {
IScreenConstructor<T, ? extends AbstractContainerScreen<T>> screen = ((RegiliteMenu<T>) menu).getScreenConstructor();
if (menu instanceof RegiliteMenu regiliteMenu) {
IScreenConstructor<T, ? extends AbstractContainerScreen<T>> screen = regiliteMenu.getScreenConstructor();

if (screen != null) {
event.enqueueWork(
() -> MenuScreens.register(((RegiliteMenu<T>) menu).get(), screen::create)
);
event.register((MenuType<T>)regiliteMenu.get(), screen::create);
}
}
}
}

public void screenEvent(FMLClientSetupEvent event) {
public void screenEvent(RegisterMenuScreensEvent event) {
this.genericScreenEvent(event);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.enderio.regilite.holder;

import com.enderio.regilite.registry.ITagagble;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
Expand All @@ -14,7 +13,6 @@
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.common.util.NonNullFunction;
import net.neoforged.neoforge.registries.DeferredHolder;
import org.jetbrains.annotations.ApiStatus;

Expand All @@ -24,11 +22,12 @@
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class RegiliteBlockEntity<T extends BlockEntity> extends DeferredHolder<BlockEntityType<? extends BlockEntity>, BlockEntityType<T>> implements ITagagble<BlockEntityType<?>> {
protected Set<TagKey<BlockEntityType<?>>> BlockEntityTags = new HashSet<>();
protected Supplier<NonNullFunction<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> renderer;
protected Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> renderer;

protected List<AttachedCapability<T, ?, ?>> attachedCapabilityList = new ArrayList<>();

Expand Down Expand Up @@ -66,12 +65,12 @@ public final RegiliteBlockEntity<T> addBlockEntityTagsTags(TagKey<BlockEntityTyp
return this;
}

public RegiliteBlockEntity<T> setRenderer(Supplier<NonNullFunction<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> renderer) {
public RegiliteBlockEntity<T> setRenderer(Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> renderer) {
this.renderer = renderer;
return this;
}

public Supplier<NonNullFunction<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> getRenderer() {
public Supplier<Function<BlockEntityRendererProvider.Context, BlockEntityRenderer<? super T>>> getRenderer() {
return renderer;
}

Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/enderio/regilite/holder/RegiliteEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

import com.enderio.regilite.Regilite;
import com.enderio.regilite.registry.ITagagble;
import com.enderio.regilite.data.RegiliteDataProvider;
import com.enderio.regilite.utils.DefaultTranslationUtility;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.neoforged.neoforge.common.util.NonNullFunction;
import net.neoforged.neoforge.registries.DeferredHolder;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

public class RegiliteEntity<T extends Entity> extends DeferredHolder<EntityType<? extends Entity>, EntityType<T>> implements ITagagble<EntityType<?>> {
private final Set<TagKey<EntityType<?>>> entityTags = new HashSet<>();
private final Supplier<String> supplier = () -> get().getDescriptionId();
private final Regilite regilite;
private Supplier<NonNullFunction<EntityRendererProvider.Context, EntityRenderer<? super T>>> renderer = null;
private Supplier<Function<EntityRendererProvider.Context, EntityRenderer<? super T>>> renderer = null;

protected RegiliteEntity(ResourceKey<EntityType<? extends Entity>> key, Regilite regilite) {
super(key);
Expand Down Expand Up @@ -51,12 +48,12 @@ public RegiliteEntity<T> setTranslation(String translation) {
return this;
}

public RegiliteEntity<T> setRenderer(Supplier<NonNullFunction<EntityRendererProvider.Context, EntityRenderer<? super T>>> renderer) {
public RegiliteEntity<T> setRenderer(Supplier<Function<EntityRendererProvider.Context, EntityRenderer<? super T>>> renderer) {
this.renderer = renderer;
return this;
}

public Supplier<NonNullFunction<EntityRendererProvider.Context, EntityRenderer<? super T>>> getRenderer() {
public Supplier<Function<EntityRendererProvider.Context, EntityRenderer<? super T>>> getRenderer() {
return renderer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public <B extends LiquidBlock, U extends FluidType> RegiliteBlock.RegiliteLiquid
}

public <U extends FluidType> RegiliteBlock.RegiliteLiquidBlock<LiquidBlock, U> registerLiquidBlock(String name, BlockBehaviour.Properties props, Supplier<FlowingFluid> fluidSupp, RegiliteFluid<U> fluid) {
return this.registerLiquidBlock(name, (rl) -> new LiquidBlock(fluidSupp, props), fluid);
return this.registerLiquidBlock(name, (rl) -> new LiquidBlock(fluidSupp.get(), props), fluid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.neoforged.fml.common.Mod;
import org.slf4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
// The value here should match an entry in the META-INF/neoforge.mods.toml file
@Mod(ExampleMod.MODID)
public class ExampleMod
{
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/enderio/regilite/examplemod/Fluids.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class Fluids {

public static final RegiliteFluid<FluidType> EXAMPLE_FLUID = FLUIDTYPES.registerFluid("example_fluid", FluidType.Properties.create())
.createFluid(FLUIDS)
.withBlock(BLOCKS, fluid -> new LiquidBlock(fluid, BlockBehaviour.Properties.ofFullCopy(Blocks.WATER)))
// TODO: Maybe make withBlock and withBucket just provide the fluid, no supplier.
.withBlock(BLOCKS, fluid -> new LiquidBlock(fluid.get(), BlockBehaviour.Properties.ofFullCopy(Blocks.WATER)))
.finishLiquidBlock()
.withBucket(ITEMS, fluid -> new BucketItem(fluid, new Item.Properties().stacksTo(1)))
.withBucket(ITEMS, fluid -> new BucketItem(fluid.get(), new Item.Properties().stacksTo(1)))
.finishBucket()
.setRenderType(() -> RenderType::translucent);

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/enderio/regilite/examplemod/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Items {
public static final ItemRegistry ITEMS = ItemRegistry.create(ExampleMod.getRegilite());

public static final RegiliteItem<Item> EXAMPLE_ITEM = ITEMS.registerItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
.alwaysEat().nutrition(1).saturationMod(2f).build()))
.alwaysEdible().nutrition(1).saturationModifier(2f).build()))
.addItemTags(ItemTags.WOOL)
.setTranslation("Test Example Item")
.setColorSupplier(() -> () -> ExampleColors.ITEM)
Expand Down
Loading

0 comments on commit 130e0c5

Please sign in to comment.