Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobgranberry committed Sep 17, 2024
1 parent e7a3757 commit d305026
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 28 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ base {
// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21.
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

//minecraft {
// accessTransformers {
// file('src/main/resources/META-INF/accesstransformer.cfg')
// }
//}

neoForge {
// Specify the version of NeoForge to use.
version = project.neo_version
Expand Down Expand Up @@ -187,3 +193,4 @@ idea {
downloadJavadoc = true
}
}

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ minecraft_version=1.21.1
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21.1, 1.22)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.1.45
neo_version=21.1.54
# The Neo version range can use any version of Neo as bounds
neo_version_range=[21.1.0,)
# The loader version range can only use the major version of FML as bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public static void dumpBlockPerf() {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(WesterosBlocks.MOD_ID);


public DeferredBlock<Block> registerBlock(String blockName, Block block) {
public DeferredBlock<Block> registerBlock(Block block) {
DeferredBlock<Block> deferredBlock = BLOCKS.register(blockName, () -> block);
registerBlockItem(blockName, deferredBlock);
return deferredBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.DeferredRegister;

// Used to define the interfaces for properly priming one of our custom block definitions
// Block definitions must also have constructor with WesterosBlockDef as parameter
Expand Down
80 changes: 55 additions & 25 deletions src/main/java/com/westeroscraft/westerosblocks/WesterosBlocks.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.westeroscraft.westerosblocks;

import com.westeroscraft.westerosblocks.blocks.AuxileryUtils;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DoorBlock;
Expand Down Expand Up @@ -29,6 +32,7 @@
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
Expand Down Expand Up @@ -73,6 +77,8 @@
import java.util.Optional;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

import com.westeroscraft.westerosblocks.network.ClientMessageHandler;
import com.westeroscraft.westerosblocks.network.PWeatherMessage;
Expand All @@ -85,11 +91,11 @@
public class WesterosBlocks {
public static final String MOD_ID = "westerosblocks";

// Network setup
public static SimpleChannel simpleChannel; // used to transmit your network messages
public static final String CHANNEL = "wbchannel";
public static final String MESSAGE_PROTOCOL_VERSION = "5.10";
public static final ResourceLocation simpleChannelRL = new ResourceLocation("westerosblocks", CHANNEL);
// Network setup TODO: FIXME NEOFORGE NETWORKING
// public static SimpleChannel simpleChannel; // used to transmit your network messages
// public static final String CHANNEL = "wbchannel";
// public static final String MESSAGE_PROTOCOL_VERSION = "5.10";
// public static final ResourceLocation simpleChannelRL = new ResourceLocation("westerosblocks", CHANNEL);

// Directly reference a log4j logger.
public static final Logger log = LogManager.getLogger();
Expand All @@ -112,8 +118,10 @@ public class WesterosBlocks {
public static WesterosItemMenuOverrides[] menuOverrides;

public WesterosBlocks(IEventBus modEventBus, ModContainer modContainer) {
// Register the doClientStuff method for modloading
modEventBus.addListener(this::doClientStuff);
if (FMLEnvironment.dist.isClient()) {
modEventBus.addListener(this::doClientStuff);
modEventBus.addListener(this::registerClientReloadListeners);
}
// Register the setup method for load complete
modEventBus.addListener(this::loadComplete);
// Register the doClientStuff method for modloading
Expand Down Expand Up @@ -151,7 +159,9 @@ public WesterosBlocks(IEventBus modEventBus, ModContainer modContainer) {

private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
log.info("Got game settings {}", event.description());
event.enqueueWork(() -> {
log.info("Got game settings {}", event.description());
});
}

@SubscribeEvent
Expand All @@ -162,6 +172,25 @@ public void onRegisterCommandEvent(RegisterCommandsEvent event) {
NVCommand.register(commandDispatcher);
}

private void registerClientReloadListeners(RegisterClientReloadListenersEvent event) {
event.registerReloadListener(new WesterosResourceReloadListener());
}

public static class WesterosResourceReloadListener implements PreparableReloadListener {
@Override
public CompletableFuture<Void> reload(PreparableReloadListener.PreparationBarrier stage, ResourceManager resourceManager,
ProfilerFiller preparationsProfiler, ProfilerFiller reloadProfiler,
Executor backgroundExecutor, Executor gameExecutor) {
return CompletableFuture.supplyAsync(() -> {
WesterosBlocks.log.info("Handling resource reload");
return null;
}, backgroundExecutor).thenCompose(stage::wait).thenAcceptAsync((v) -> {
WesterosBlockDef.reloadColorHandler(resourceManager);
WesterosBlocks.log.info("Handling resource reload completed");
}, gameExecutor);
}
}

private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationEven
{
// Initialize with standard block IDs
Expand All @@ -175,27 +204,27 @@ private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationE
deleteDirectory(new File(modConfigPath.toFile(), "assets"));
deleteDirectory(new File(modConfigPath.toFile(), "data"));

for (int i = 0; i < customBlockDefs.length; i++) {
if (customBlockDefs[i] == null)
for (WesterosBlockDef customBlockDef : customBlockDefs) {
if (customBlockDef == null)
continue;
Block blk = customBlocksByName.get(customBlockDefs[i].blockName);
Block blk = customBlocksByName.get(customBlockDef.blockName);
if (blk != null) {
ModelExport exp = ModelExportFactory.forBlock(blk, customBlockDefs[i], modConfigPath.toFile());
ModelExport exp = ModelExportFactory.forBlock(blk, customBlockDef, modConfigPath.toFile());
if (exp != null) {
try {
exp.doBlockStateExport();
exp.doModelExports();
// If list, roll through choices as legacyBlockID
if (customBlockDefs[i].legacyBlockIDList != null) {
for (String legacyid : customBlockDefs[i].legacyBlockIDList) {
customBlockDefs[i].legacyBlockID = legacyid;
// If it's a list, roll through choices as legacyBlockID
if (customBlockDef.legacyBlockIDList != null) {
for (String legacyid : customBlockDef.legacyBlockIDList) {
customBlockDef.legacyBlockID = legacyid;
exp.doWorldConverterMigrate();
ModelExport.addWorldConverterItemMap(legacyid, customBlockDefs[i].blockName);
ModelExport.addWorldConverterItemMap(legacyid, customBlockDef.blockName);
}
customBlockDefs[i].legacyBlockID = null;
} else if (customBlockDefs[i].legacyBlockID != null) {
customBlockDef.legacyBlockID = null;
} else if (customBlockDef.legacyBlockID != null) {
exp.doWorldConverterMigrate();
ModelExport.addWorldConverterItemMap(customBlockDefs[i].legacyBlockID, customBlockDefs[i].blockName);
ModelExport.addWorldConverterItemMap(customBlockDef.legacyBlockID, customBlockDef.blockName);
}
} catch (IOException iox) {
log.warn(String.format("Error exporting block %s - %s", blk.getName(), iox));
Expand Down Expand Up @@ -234,7 +263,7 @@ private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationE
log.warn(String.format("Error writing WorldConfig item mapping - %s", iox));
}
}
proxy.initRenderRegistry();
// proxy.initRenderRegistry();

}

Expand Down Expand Up @@ -412,7 +441,8 @@ public void buildContents(BuildCreativeModeTabContentsEvent event) {
for (WesterosItemMenuOverrides mo : menuOverrides) {
if (mo.blockNames != null) {
for (String bn : mo.blockNames) {
Item itm = ForgeRegistries.ITEMS.getValue(new ResourceLocation(bn));
Item itm = ForgeRegistries.ITEMS.getValue(ResourceLocation.fromNamespaceAndPath(MOD_ID, bn));

if (itm == null) {
log.warn("Item for " + bn + " not found - cannot override");
} else {
Expand Down Expand Up @@ -496,8 +526,8 @@ public static WesterosBlockDef[] getBlockDefs(WesterosBlockConfig config) {
public static Block findBlockByName(String blkname) {
Block blk = customBlocksByName.get(blkname);
if (blk != null) return blk;
ResourceLocation rl = new ResourceLocation(blkname);
if (rl.getNamespace().equals(WesterosBlocks.MOD_ID)) {
ResourceLocation rl = ResourceLocation.fromNamespaceAndPath(MOD_ID, blkname);
if (rl.getNamespace().equals(MOD_ID)) {
blk = customBlocksByName.get(rl.getPath());
}
if (blk != null) {
Expand Down Expand Up @@ -535,7 +565,7 @@ public static boolean validateDefs(WesterosBlockDef[] defs) {
public static SoundEvent registerSound(String soundName) {
SoundEvent event = registered_sounds.get(soundName);
if (event == null) {
ResourceLocation location = new ResourceLocation(WesterosBlocks.MOD_ID, soundName);
ResourceLocation location = ResourceLocation.fromNamespaceAndPath(WesterosBlocks.MOD_ID, soundName);
event = SoundEvent.createVariableRangeEvent(location);
//event.setRegistryName(location);
ForgeRegistries.SOUND_EVENTS.register(location, event);
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public net.minecraft.network.protocol.game.ClientboundGameEventPacket f_132165_ # event
public net.minecraft.network.protocol.game.ClientboundGameEventPacket f_132166_ # param
public-f net.minecraft.network.protocol.game.ClientboundSetTimePacket f_133345_ # gameTime
public-f net.minecraft.network.protocol.game.ClientboundSetTimePacket f_133346_ # dayTime
public net.minecraft.world.level.block.WallBlock f_57955_ # shapeByIndex
public net.minecraft.world.level.block.WallBlock f_57956_ # collisionShapeByIndex
public net.minecraft.world.level.block.WallBlock m_57965_(FFFFFF)Ljava/util/Map; # makeShapes
public net.minecraft.world.level.biome.Biome f_47437_ # climateSettings
public net.minecraft.world.level.biome.Biome m_47505_(Lnet/minecraft/core/BlockPos;)F # getTemperature
public net.minecraft.world.level.biome.Biome m_47528_(Lnet/minecraft/core/BlockPos;)F # getHeightAdjustedTemperature
public net.minecraft.client.renderer.chunk.RenderChunkRegion f_112908_ # level
public-f net.minecraft.world.level.biome.Biome$ClimateSettings f_47681_ # temperature
public-f net.minecraft.world.level.biome.Biome$ClimateSettings f_47680_ # precipitation
public-f net.minecraft.world.item.Item f_41377_ # category
public-f net.minecraft.world.item.CreativeModeTab f_40762_ # id
public-f net.minecraft.client.renderer.BiomeColors f_108791_ # WATER_COLOR_RESOLVER

0 comments on commit d305026

Please sign in to comment.