Skip to content

Commit

Permalink
Merge pull request #16 from ChampionAsh5357/feat/poi
Browse files Browse the repository at this point in the history
Add Point of Interest Types for Existing Slab Machines
  • Loading branch information
Mrbysco authored Oct 3, 2024
2 parents b452ad5 + 706c2ca commit b0a81a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/mrbysco/slabmachines/SlabMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent;
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
Expand All @@ -25,6 +26,7 @@ public SlabMachines(IEventBus eventBus, Dist dist, ModContainer container) {
container.registerConfig(ModConfig.Type.COMMON, SlabConfig.commonSpec);
eventBus.register(SlabConfig.class);

eventBus.addListener(this::commonSetupEvent);
eventBus.addListener(this::interModEnqueueEvent);
eventBus.addListener(SlabRegistry::registerCapabilities);

Expand All @@ -49,4 +51,8 @@ public void interModEnqueueEvent(InterModEnqueueEvent event) {
return tagCompound;
});
}

public void commonSetupEvent(FMLCommonSetupEvent event) {
event.enqueueWork(SlabRegistry::registerPointOfInterests);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/mrbysco/slabmachines/init/SlabRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@
import com.mrbysco.slabmachines.blocks.TrappedChestSlabBlock;
import com.mrbysco.slabmachines.entity.TNTSlabEntity;
import com.mrbysco.slabmachines.menu.SlabBenchMenu;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand All @@ -36,6 +42,7 @@
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.GameData;

import java.util.List;
import java.util.function.Supplier;
Expand Down Expand Up @@ -101,4 +108,19 @@ public static void registerCapabilities(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, CHEST_SLAB_BE.get(), (chestSlabBlock, side) ->
new InvWrapper(chestSlabBlock));
}

public static void registerPointOfInterests() {
registerAllStatesToPointOfInterest(PoiTypes.ARMORER, BLAST_FURNACE_SLAB);
registerAllStatesToPointOfInterest(PoiTypes.BUTCHER, SMOKER_SLAB);
}

@SafeVarargs
private static void registerAllStatesToPointOfInterest(ResourceKey<PoiType> poi, Supplier<? extends Block>... blocks) {
Holder<PoiType> poiHolder = BuiltInRegistries.POINT_OF_INTEREST_TYPE.getHolderOrThrow(poi);
for (var block : blocks) {
block.get().getStateDefinition().getPossibleStates().forEach(
state -> GameData.getBlockStatePointOfInterestTypeMap().put(state, poiHolder)
);
}
}
}

0 comments on commit b0a81a1

Please sign in to comment.