Skip to content

Instantly share code, notes, and snippets.

@zmatez
Created November 2, 2020 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmatez/e53a0f34afa79b80aef9909047c43ac5 to your computer and use it in GitHub Desktop.
Save zmatez/e53a0f34afa79b80aef9909047c43ac5 to your computer and use it in GitHub Desktop.
package com.matez.wildnature.util.event;
import com.matez.wildnature.init.Main;
import com.matez.wildnature.util.dataFixer.WNDataFixer;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class DataFixEvent {
@SubscribeEvent
public void fixBlocks(RegistryEvent.MissingMappings<Block> event) {
Main.LOGGER.info("---> Remapping blocks");
int remapped = 0;
int errors = 0;
int ignored = 0;
List<RegistryEvent.MissingMappings.Mapping<Block>> list = event.getAllMappings();
LinkedHashMap<ResourceLocation, ResourceLocation> renameMap = Main.dataFixer.getBlockRemap();
for (RegistryEvent.MissingMappings.Mapping<Block> mapping : list) {
ResourceLocation oldLoc = mapping.key;
ResourceLocation newLoc = renameMap.get(oldLoc);
if (newLoc != null) {
Block block = ForgeRegistries.BLOCKS.getValue(newLoc);
if (block != null && block != Blocks.AIR) {
mapping.remap(block);
Main.LOGGER.debug("Re-mapped block '{}' => '{}'", oldLoc.toString(), newLoc.toString());
remapped++;
}else{
Main.LOGGER.error("Couldn't re-map block '{}' !=> '{}': new mapping isn't registered ", oldLoc.toString(), newLoc.toString());
errors++;
}
}else{
if(oldLoc.getNamespace().equals("wildnature")){
Main.LOGGER.debug("Ignoring mapping for block id '{}'", oldLoc.toString());
mapping.ignore();
ignored++;
}
}
}
Main.LOGGER.info("---> Remapped " + remapped + " with " + errors + " errors. Ignored " + ignored + " mappings.");
}
/*@SubscribeEvent
public void fixItems(RegistryEvent.MissingMappings<Item> event) {
Main.LOGGER.info("---> Remapping items");
int remapped = 0;
int errors = 0;
List<RegistryEvent.MissingMappings.Mapping<Item>> list = event.getAllMappings();
LinkedHashMap<ResourceLocation, ResourceLocation> renameMap = Main.dataFixer.getItemRemap();
for (RegistryEvent.MissingMappings.Mapping<Item> mapping : list) {
ResourceLocation oldLoc = mapping.key;
ResourceLocation newLoc = renameMap.get(oldLoc);
if (newLoc != null) {
Item item = ForgeRegistries.ITEMS.getValue(newLoc);
if (item != null && item != Items.AIR) {
mapping.remap(item);
Main.LOGGER.debug("Re-mapped item '{}' => '{}'", oldLoc.toString(), newLoc.toString());
remapped++;
}else{
Main.LOGGER.error("Couldn't re-map item '{}' !=> '{}': new mapping isn't registered ", oldLoc.toString(), newLoc.toString());
errors++;
}
}
}
Main.LOGGER.info("---> Remapped " + remapped + " with " + errors + " errors.");
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment