Skip to content

Commit

Permalink
Misc cleanup relating to how we reference the registry access of a pl…
Browse files Browse the repository at this point in the history
…ayer's level
  • Loading branch information
pupnewfster committed Jan 18, 2025
1 parent 5926dce commit 83fcef4
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/mekanism/common/content/gear/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void toggleEnabled(IModuleContainer moduleContainer, ItemStack stack, Pla
message = MekanismLang.GENERIC_STORED.translate(modeName, EnumColor.BRIGHT_GREEN, MekanismLang.MODULE_ENABLED_LOWER);
}
player.displayClientMessage(message, true);
((ModuleContainer) moduleContainer).toggleEnabled(player.level().registryAccess(), stack, data);
((ModuleContainer) moduleContainer).toggleEnabled(player.registryAccess(), stack, data);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void changeMode(IModule<ModuleJetpackUnit> module, Player player, IModule
if (displayChangeMessage) {
module.displayModeChange(player, MekanismLang.MODULE_JETPACK_MODE.translate(), newMode);
}
moduleContainer.replaceModuleConfig(player.level().registryAccess(), stack, module.getData(), module.<JetpackMode>getConfigOrThrow(JETPACK_MODE).with(newMode));
moduleContainer.replaceModuleConfig(player.registryAccess(), stack, module.getData(), module.<JetpackMode>getConfigOrThrow(JETPACK_MODE).with(newMode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void changeMode(IModule<ModuleLocomotiveBoostingUnit> module, Player play
if (displayChangeMessage) {
module.displayModeChange(player, MekanismLang.MODULE_SPRINT_BOOST.translate(), newMode);
}
moduleContainer.replaceModuleConfig(player.level().registryAccess(), stack, module.getData(), module.<SprintBoost>getConfigOrThrow(SPRINT_BOOST).with(newMode));
moduleContainer.replaceModuleConfig(player.registryAccess(), stack, module.getData(), module.<SprintBoost>getConfigOrThrow(SPRINT_BOOST).with(newMode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public <MODE extends IRadialMode> boolean setMode(IModule<ModuleBlastingUnit> mo
if (radialData == getRadialData(module)) {
BlastRadius newMode = (BlastRadius) mode;
if (blastRadius != newMode) {
moduleContainer.replaceModuleConfig(player.level().registryAccess(), stack, module.getData(), module.<BlastRadius>getConfigOrThrow(BLAST_RADIUS).with(newMode));
moduleContainer.replaceModuleConfig(player.registryAccess(), stack, module.getData(), module.<BlastRadius>getConfigOrThrow(BLAST_RADIUS).with(newMode));
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public <MODE extends IRadialMode> boolean setMode(IModule<ModuleExcavationEscala
if (radialData == getRadialData(module)) {
ExcavationMode newMode = (ExcavationMode) mode;
if (excavationMode != newMode) {
moduleContainer.replaceModuleConfig(player.level().registryAccess(), stack, module.getData(), module.<ExcavationMode>getConfigOrThrow(EXCAVATION_MODE).with(newMode));
moduleContainer.replaceModuleConfig(player.registryAccess(), stack, module.getData(), module.<ExcavationMode>getConfigOrThrow(EXCAVATION_MODE).with(newMode));
}
}
return false;
Expand All @@ -104,7 +104,7 @@ public void changeMode(IModule<ModuleExcavationEscalationUnit> module, Player pl
if (displayChangeMessage) {
module.displayModeChange(player, MekanismLang.MODULE_EFFICIENCY.translate(), newMode);
}
moduleContainer.replaceModuleConfig(player.level().registryAccess(), stack, module.getData(), module.<ExcavationMode>getConfigOrThrow(EXCAVATION_MODE).with(newMode));
moduleContainer.replaceModuleConfig(player.registryAccess(), stack, module.getData(), module.<ExcavationMode>getConfigOrThrow(EXCAVATION_MODE).with(newMode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public <MODE extends IRadialMode> MODE getMode(IModule<ModuleVeinMiningUnit> mod
public <MODE extends IRadialMode> boolean setMode(IModule<ModuleVeinMiningUnit> module, Player player, IModuleContainer moduleContainer, ItemStack stack, RadialData<MODE> radialData, MODE mode) {
if (radialData == RADIAL_DATA && MekanismConfig.gear.mekaToolExtendedMining.get()) {
if (extended == (mode != RADIAL_MODES.trueMode())) {
toggleExtended(module, moduleContainer, stack, player.level().registryAccess());
toggleExtended(module, moduleContainer, stack, player.registryAccess());
}
}
return false;
Expand All @@ -120,7 +120,7 @@ public void changeMode(IModule<ModuleVeinMiningUnit> module, Player player, IMod
if (displayChangeMessage) {
player.sendSystemMessage(MekanismUtils.logFormat(MekanismLang.MODULE_MODE_CHANGE.translate(MekanismLang.MODULE_EXTENDED_MODE, EnumColor.INDIGO, !extended)));
}
toggleExtended(module, moduleContainer, stack, player.level().registryAccess());
toggleExtended(module, moduleContainer, stack, player.registryAccess());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public void flushCachedTag() {
if (filterTag == null) {
setSelectedOutput(getFallbackElement());
} else if (!filterTag.contains(selectedOutput)) {
filterTag.stream().findFirst().ifPresentOrElse(this::setSelectedOutput, this::setToFallback);
if (filterTag.size() == 0) {
setToFallback();
} else {
setSelectedOutput(filterTag.get(0));
}
}
//Note: Even though the tag instance may have changed, we don't need to reset the cached
// stack if the tag still contains the selected output as that means it is not empty and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public void broadcastChanges() {
if (inv.player instanceof ServerPlayer player) {
//Only check tracked data for changes if we actually have any listeners
List<PropertyData> dirtyData = new ArrayList<>();
RegistryAccess registryAccess = player.level().registryAccess();
RegistryAccess registryAccess = player.registryAccess();
for (short i = 0; i < trackedData.size(); i++) {
ISyncableData data = trackedData.get(i);
DirtyType dirtyType = data.isDirty();
Expand All @@ -665,7 +665,7 @@ private void sendInitialDataToRemote(List<ISyncableData> syncableData, ShortUnar
if (inv.player instanceof ServerPlayer player) {
//Send all contents to the listener when it first gets added
List<PropertyData> dirtyData = new ArrayList<>();
RegistryAccess registryAccess = player.level().registryAccess();
RegistryAccess registryAccess = player.registryAccess();
for (short i = 0; i < syncableData.size(); i++) {
ISyncableData data = syncableData.get(i);
//Query if the data is dirty or not so that we update our last known value to the initial values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static float getDamageAbsorbed(Player player, DamageSource source, float
} else {
// Note: In theory the above path should always be done as vanilla only makes damage sources with reference holders
// but just in case have the fallback to look up the name from the registry
Optional<Registry<DamageType>> registry = player.level().registryAccess().registry(Registries.DAMAGE_TYPE);
Optional<Registry<DamageType>> registry = player.registryAccess().registry(Registries.DAMAGE_TYPE);
if (registry.isPresent()) {
absorptionData = registry.get().wrapAsHolder(source.type()).getData(MekanismDataMapTypes.MEKA_SUIT_ABSORPTION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void handle(IPayloadContext context) {
//Validate the container still has the container, and it didn't end up somehow getting removed by the time the server received the packet
if (container != null && container.has(target.moduleType())) {
try {
container.replaceModuleConfig(player.level().registryAccess(), stack, target.moduleType(), target.config(), true);
container.replaceModuleConfig(player.registryAccess(), stack, target.moduleType(), target.config(), true);
} catch (IllegalArgumentException | IllegalStateException e) {
//If the packet is invalid, for example if a config got sent setting to an enum value that is not in range
// or if a module config with the given name couldn't be found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ private MekanismArmorMaterials() {

public static final MekanismDeferredRegister<ArmorMaterial> ARMOR_MATERIALS = new MekanismDeferredRegister<>(Registries.ARMOR_MATERIAL, Mekanism.MODID);

public static final MekanismDeferredHolder<ArmorMaterial, ArmorMaterial> HAZMAT = ARMOR_MATERIALS.register("hazmat", () -> new ArmorMaterial(
public static final MekanismDeferredHolder<ArmorMaterial, ArmorMaterial> HAZMAT = ARMOR_MATERIALS.register("hazmat", rl -> new ArmorMaterial(
Collections.emptyMap(), 0, SoundEvents.ARMOR_EQUIP_GENERIC, () -> Ingredient.EMPTY,
List.of(new ArmorMaterial.Layer(Mekanism.rl("hazmat"))), 0, 0
List.of(new ArmorMaterial.Layer(rl)), 0, 0
));
public static final MekanismDeferredHolder<ArmorMaterial, ArmorMaterial> SCUBA_GEAR = registerBaseSpecial("scuba_gear");
public static final MekanismDeferredHolder<ArmorMaterial, ArmorMaterial> FREE_RUNNERS = registerBaseSpecial("free_runners");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void removeModule(Player player, ModuleData<?> type, boolean removeAll) {
if (installed > 0) {
int toRemove = removeAll ? installed : 1;
if (player.getInventory().add(type.getItemProvider().getItemStack(toRemove))) {
container.removeModule(player.level().registryAccess(), stack, type, toRemove);
container.removeModule(player.registryAccess(), stack, type, toRemove);
containerSlot.setStack(stack);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -65,10 +64,10 @@
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemStackLinkedSet;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.util.ItemStackMap;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -519,7 +518,7 @@ ItemStack getOutput(int process) throws ComputerException {
//End methods IComputerTile

private void sortInventory() {
Map<ItemStack, RecipeProcessInfo<RECIPE>> processes = new Object2ObjectOpenCustomHashMap<>(ItemStackLinkedSet.TYPE_AND_TAG);
Map<ItemStack, RecipeProcessInfo<RECIPE>> processes = ItemStackMap.createTypeAndTagMap();
List<ProcessInfo> emptyProcesses = new ArrayList<>();
for (ProcessInfo processInfo : processInfoSlots) {
IInventorySlot inputSlot = processInfo.inputSlot();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mekanism/common/util/RegistryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jetbrains.annotations.Nullable;

//TODO - 1.21: Re-evaluate this class and the fact that the getNames don't bother handling that for defaulted registries the default key is returned
// See also Util#getRegisteredName
public class RegistryUtils {

private RegistryUtils() {
Expand Down

0 comments on commit 83fcef4

Please sign in to comment.