Skip to content

Commit

Permalink
Neoforge and actually fixed the microwave
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Jan 2, 2024
1 parent ed22a2f commit a4b4a80
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void handledScreenTick() {
this.isActive = handler.isActive;
DefaultedList<ItemStack> inventory = DefaultedList.ofSize(1,handler.getInventory().getStack(0));
Optional<RecipeEntry<SmokingRecipe>> recipe = getRecipe(handler.microwaveBlockEntity.getWorld(), handler.getInventory());
if(recipe.isPresent() && microwaveBlockEntity.getWorld() != null && !MicrowaveBlockEntity.canAcceptRecipeOutput(microwaveBlockEntity.getWorld().getRegistryManager(), recipe.get() != null ? recipe.get().value() : null, inventory ,microwaveBlockEntity.getMaxCountPerStack()) && !this.handler.isActive()) {
if(recipe.isEmpty() || !MicrowaveBlockEntity.canAcceptRecipeOutput(microwaveBlockEntity.getWorld().getRegistryManager(), recipe.<Recipe<?>>map(RecipeEntry::value).orElse(null), inventory, microwaveBlockEntity.getMaxCountPerStack()) && !this.handler.isActive()) {
this.startButton.active = false;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.minecraft.screen.slot.Slot;
import net.minecraft.world.World;

import java.util.Optional;

public abstract class AbstractMicrowaveScreenHandler extends AbstractRecipeScreenHandler<Inventory> {
private final Inventory inventory;
private final PropertyDelegate propertyDelegate;
Expand Down Expand Up @@ -173,8 +175,8 @@ protected boolean insertItemToSlot(ItemStack stack, int startIndex, int endIndex
}

protected boolean isCookable(ItemStack itemStack) {
RecipeEntry<? extends AbstractCookingRecipe> entry = this.world.getRecipeManager().getFirstMatch(this.recipeType, new SimpleInventory(itemStack), this.world).orElseGet(null);
return entry != null && entry.value() != null;
Optional<? extends RecipeEntry<? extends AbstractCookingRecipe>> optionalRecipeEntry = this.world.getRecipeManager().getFirstMatch(this.recipeType, new SimpleInventory(itemStack), this.world);
return optionalRecipeEntry != null && optionalRecipeEntry.isPresent() && optionalRecipeEntry.get().value() != null;
}

public int getCookProgress() {
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/resources/pfm.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ accessible field net/minecraft/resource/featuretoggle/FeatureSet universe Lnet/m
accessible field net/minecraft/resource/featuretoggle/FeatureSet featuresMask J
mutable field net/minecraft/resource/featuretoggle/FeatureFlag mask J
accessible field net/minecraft/resource/featuretoggle/FeatureFlag mask J
accessible class net/minecraft/data/server/tag/TagProvider$ProvidedTagBuilder
accessible class net/minecraft/data/server/tag/TagProvider$ProvidedTagBuilder
accessible field net/minecraft/world/poi/PointOfInterestType blockStates Ljava/util/Set;
mutable field net/minecraft/world/poi/PointOfInterestType blockStates Ljava/util/Set;
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ public static void initializeItemGroup() {
}

public static void replaceHomePOI() {
Set<BlockState> addedBedStates = PaladinFurnitureModBlocksItems.beds.stream().flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> newBedStates = new HashSet<>();
newBedStates.addAll(PaladinFurnitureModBlocksItems.originalHomePOIBedStates);
newBedStates.addAll(originalBedStates);
newBedStates.addAll(addedBedStates);
newBedStates = newBedStates.stream().collect(ImmutableSet.toImmutableSet());
PointOfInterestType pointOfInterestType = new PointOfInterestType(newBedStates, 1, 1);
PointOfInterestTypes.HOME = ((SimpleRegistry<PointOfInterestType>)Registries.POINT_OF_INTEREST_TYPE).set(Registries.POINT_OF_INTEREST_TYPE.getRawId(Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME)), PointOfInterestTypes.HOME, pointOfInterestType, Lifecycle.stable()).getKey().get();
PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME);
homePOI.blockStates = ImmutableSet.copyOf(newBedStates);
}
@Override
public void onInitializeServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeType;
import net.minecraft.registry.Registries;
import net.minecraft.util.Pair;
import net.minecraft.world.poi.PointOfInterestType;
import net.minecraft.world.poi.PointOfInterestTypes;
Expand Down Expand Up @@ -68,14 +69,13 @@ public static void registerBlocks(IForgeRegistry<Block> blockRegisterEvent) {
}
blocks.forEach(blockRegisterEvent::register);

Set<BlockState> originalBedStates = ForgeRegistries.POI_TYPES.getValue(PointOfInterestTypes.HOME.getValue()).blockStates();
Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> newBedStates = new HashSet<>();
newBedStates.addAll(originalBedStates);
newBedStates.addAll(addedBedStates);
PointOfInterestType pointOfInterestType = new PointOfInterestType(newBedStates, 1, 1);
ForgeRegistries.POI_TYPES.register("minecraft:home", pointOfInterestType);
PointOfInterestTypes.HOME = ForgeRegistries.POI_TYPES.getHolder(pointOfInterestType).get().getKey().get();
PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME);
homePOI.blockStates = ImmutableSet.copyOf(newBedStates);
}

public static void registerItems(IForgeRegistry<Item> itemIForgeRegistry) {
Expand Down
8 changes: 6 additions & 2 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ architectury {
neoForge()
}

loom {
accessWidenerPath = project(":common").loom.accessWidenerPath
}

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
Expand Down Expand Up @@ -78,7 +82,7 @@ if (rootProject.immersive_portals_compatibility_forge == "true"){

if (rootProject.lazy_dfu_enabled == "true"){
dependencies {
modRuntimeOnly ("curse.maven:lazydfu-460819:${rootProject.lazy_dfu_version_forge}")
// modRuntimeOnly ("curse.maven:lazydfu-460819:${rootProject.lazy_dfu_version_forge}")
}
}

Expand Down Expand Up @@ -112,7 +116,7 @@ sourceSets.main.resources {
}

remapJar {
atAccessWideners.add(project(":common").loom.accessWidenerPath.get().asFile.name)
atAccessWideners.add(loom.accessWidenerPath.get().asFile.name)
input.set shadowJar.archiveFile
dependsOn shadowJar
archiveClassifier = "neoforge-mc${rootProject.minecraft_version}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unlikepaladin.pfm.blocks.models.classicTable.forge;
package com.unlikepaladin.pfm.blocks.models.classicTable.neoforge;

import com.unlikepaladin.pfm.blocks.ClassicTableBlock;
import com.unlikepaladin.pfm.blocks.models.neoforge.ModelBitSetProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unlikepaladin.pfm.blocks.models.classicTable.forge;
package com.unlikepaladin.pfm.blocks.models.classicTable.neoforge;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.unlikepaladin.pfm.registry.dynamic.neoforge;

import com.google.common.collect.ImmutableSet;
import com.mojang.serialization.Lifecycle;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.blocks.AbstractSittableBlock;
import com.unlikepaladin.pfm.blocks.SimpleBedBlock;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.SimpleRegistry;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.world.poi.PointOfInterestType;
Expand Down Expand Up @@ -69,14 +71,13 @@ public static void registerBlocks(Registry<Block> blockRegisterEvent) {
}
blocks.forEach((blockName, block) -> Registry.register(Registries.BLOCK, new Identifier(PaladinFurnitureMod.MOD_ID, blockName), block));

Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME.getValue()).blockStates();
Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> newBedStates = new HashSet<>();
newBedStates.addAll(originalBedStates);
newBedStates.addAll(addedBedStates);
PointOfInterestType pointOfInterestType = new PointOfInterestType(newBedStates, 1, 1);
Registry.register(Registries.POINT_OF_INTEREST_TYPE, new Identifier("minecraft", "home"), pointOfInterestType);
PointOfInterestTypes.HOME = Registries.POINT_OF_INTEREST_TYPE.getKey(pointOfInterestType).get();
PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME);
homePOI.blockStates = ImmutableSet.copyOf(newBedStates);
}

public static void registerItems(Registry<Item> itemIForgeRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.advancements.PFMCriteria;
import com.unlikepaladin.pfm.networking.neoforge.*;
import net.minecraft.server.network.ServerPlayerConfigurationTask;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.neoforged.bus.api.SubscribeEvent;
Expand All @@ -15,11 +14,13 @@

@Mod.EventBusSubscriber(modid = "pfm", bus = Mod.EventBusSubscriber.Bus.FORGE)
public class NetworkRegistryNeoForge {

public static final SimpleChannel PFM_CHANNEL = NetworkRegistry.ChannelBuilder.named(
new Identifier(PaladinFurnitureMod.MOD_ID, "main_channel")
).networkProtocolVersion(() -> "1").simpleChannel();

private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel PFM_CHANNEL = NetworkRegistry.newSimpleChannel(
new Identifier(PaladinFurnitureMod.MOD_ID, "main_channel"),
() -> PROTOCOL_VERSION,
PROTOCOL_VERSION::equals,
PROTOCOL_VERSION::equals
);

public static void registerPackets() {
int id = 0;
Expand Down

0 comments on commit a4b4a80

Please sign in to comment.