Rename POTIONS to MOB_EFFECTS for newer forge versions

This commit is contained in:
Marcel Konrad
2021-09-10 17:09:25 +02:00
parent f9de298b65
commit 700803a286
5 changed files with 22 additions and 32 deletions

View File

@@ -48,77 +48,67 @@ public abstract class ComponentPotion implements IBuilderComponent
public void setAmplifier(MobEffect potion, byte amplifier) public void setAmplifier(MobEffect potion, byte amplifier)
{ {
this.getMetadata(potion).setAmplifier(amplifier); this.get(potion).setAmplifier(amplifier);
} }
public byte getAmplifier(MobEffect potion) public byte getAmplifier(MobEffect potion)
{ {
return this.getMetadata(potion).getAmplifier(); return this.get(potion).getAmplifier();
} }
public void setSeconds(MobEffect potion, int seconds) public void setSeconds(MobEffect potion, int seconds)
{ {
this.getMetadata(potion).setSeconds(seconds); this.get(potion).setSeconds(seconds);
} }
public int getSeconds(MobEffect potion) public int getSeconds(MobEffect potion)
{ {
return this.getMetadata(potion).getSeconds(); return this.get(potion).getSeconds();
} }
public void setMinutes(MobEffect potion, int minutes) public void setMinutes(MobEffect potion, int minutes)
{ {
this.getMetadata(potion).setMinutes(minutes); this.get(potion).setMinutes(minutes);
} }
public int getMinutes(MobEffect potion) public int getMinutes(MobEffect potion)
{ {
return this.getMetadata(potion).getMinutes(); return this.get(potion).getMinutes();
} }
public void setHours(MobEffect potion, int hours) public void setHours(MobEffect potion, int hours)
{ {
this.getMetadata(potion).setHours(hours); this.get(potion).setHours(hours);
} }
public int getHours(MobEffect potion) public int getHours(MobEffect potion)
{ {
return this.getMetadata(potion).getHours(); return this.get(potion).getHours();
} }
public void setShowParticles(MobEffect potion, boolean showParticles) public void setShowParticles(MobEffect potion, boolean showParticles)
{ {
this.getMetadata(potion).setShowParticles(showParticles); this.get(potion).setShowParticles(showParticles);
} }
public boolean getShowParticles(MobEffect potion) public boolean getShowParticles(MobEffect potion)
{ {
return this.getMetadata(potion).getShowParticles(); return this.get(potion).getShowParticles();
} }
public void setAmbient(MobEffect potion, boolean ambient) public void setAmbient(MobEffect potion, boolean ambient)
{ {
this.getMetadata(potion).setAmbient(ambient); this.get(potion).setAmbient(ambient);
} }
public boolean getAmbient(MobEffect potion) public boolean getAmbient(MobEffect potion)
{ {
return this.getMetadata(potion).getAmbient(); return this.get(potion).getAmbient();
} }
private EffectNBT getMetadata(MobEffect potion) private EffectNBT get(MobEffect potion)
{ {
return this.potions.get(this.validate(potion)); return this.potions.computeIfAbsent(potion, key -> new EffectNBT());
}
private MobEffect validate(MobEffect potion)
{
if(!this.potions.containsKey(potion))
{
this.potions.put(potion, new EffectNBT());
}
return potion;
} }
public Set<MobEffect> getMobEffects() public Set<MobEffect> getMobEffects()

View File

@@ -75,7 +75,7 @@ public class BuilderPotionEffect extends CommandBuilder
if(location != null) if(location != null)
{ {
return ForgeRegistries.POTIONS.getValue(location); return ForgeRegistries.MOB_EFFECTS.getValue(location);
} }
return null; return null;

View File

@@ -63,7 +63,7 @@ public class ContentPotions extends ContentChild
@Override @Override
public void initGui(Container container, int x, int y) public void initGui(Container container, int x, int y)
{ {
MenuPageList<MobEffect> potions = new MenuPageList<MobEffect>(x, y, new ArrayList<MobEffect>(ForgeRegistries.POTIONS.getValues()), 114, 20, 3, container, new ILogicPageList<MobEffect>() MenuPageList<MobEffect> potions = new MenuPageList<MobEffect>(x, y, new ArrayList<MobEffect>(ForgeRegistries.MOB_EFFECTS.getValues()), 114, 20, 3, container, new ILogicPageList<MobEffect>()
{ {
@Override @Override
public MutableComponent translate(MobEffect item) public MutableComponent translate(MobEffect item)

View File

@@ -316,7 +316,7 @@ public class ContentSummon extends Content
for(ResourceLocation location : this.sortedPotions()) for(ResourceLocation location : this.sortedPotions())
{ {
MobEffect potion = ForgeRegistries.POTIONS.getValue(location); MobEffect potion = ForgeRegistries.MOB_EFFECTS.getValue(location);
if(!potion.equals(MobEffects.HARM) && !potion.equals(MobEffects.HEAL)) if(!potion.equals(MobEffects.HARM) && !potion.equals(MobEffects.HEAL))
{ {
@@ -325,7 +325,7 @@ public class ContentSummon extends Content
button1.active = false; button1.active = false;
} }
if(this.potionPage == ForgeRegistries.POTIONS.getKeys().size() - 3) if(this.potionPage == ForgeRegistries.MOB_EFFECTS.getKeys().size() - 3)
{ {
button2.active = false; button2.active = false;
} }
@@ -431,7 +431,7 @@ public class ContentSummon extends Content
} }
else if(Page.POTIONS.equals(this.page)) else if(Page.POTIONS.equals(this.page))
{ {
Minecraft.getInstance().font.draw(matrix, (this.potionPage + 1) + "/" + (ForgeRegistries.POTIONS.getKeys().size() - 2), x + 118, y - 11, Config.getSkin().getHeadlineColor()); Minecraft.getInstance().font.draw(matrix, (this.potionPage + 1) + "/" + (ForgeRegistries.MOB_EFFECTS.getKeys().size() - 2), x + 118, y - 11, Config.getSkin().getHeadlineColor());
} }
else if(Page.EQUIPMENT.equals(this.page)) else if(Page.EQUIPMENT.equals(this.page))
{ {
@@ -459,8 +459,8 @@ public class ContentSummon extends Content
private List<ResourceLocation> sortedPotions() private List<ResourceLocation> sortedPotions()
{ {
return ForgeRegistries.POTIONS.getKeys().stream() return ForgeRegistries.MOB_EFFECTS.getKeys().stream()
.sorted((a, b) -> I18n.get(ForgeRegistries.POTIONS.getValue(a).getDescriptionId()).compareTo(I18n.get(ForgeRegistries.POTIONS.getValue(b).getDescriptionId()))) .sorted((a, b) -> I18n.get(ForgeRegistries.MOB_EFFECTS.getValue(a).getDescriptionId()).compareTo(I18n.get(ForgeRegistries.MOB_EFFECTS.getValue(b).getDescriptionId())))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@@ -33,7 +33,7 @@ public class RegistryHelper
{ {
registerRegistry(ForgeRegistries.BLOCKS, Block::getDescriptionId); registerRegistry(ForgeRegistries.BLOCKS, Block::getDescriptionId);
registerRegistry(ForgeRegistries.ITEMS, Item::getDescriptionId); registerRegistry(ForgeRegistries.ITEMS, Item::getDescriptionId);
registerRegistry(ForgeRegistries.POTIONS, MobEffect::getDescriptionId); registerRegistry(ForgeRegistries.MOB_EFFECTS, MobEffect::getDescriptionId);
registerRegistry(ForgeRegistries.BIOMES, biome -> registerRegistry(ForgeRegistries.BIOMES, biome ->
{ {
Registry<Biome> registry = RegistryAccess.builtin().registryOrThrow(Registry.BIOME_REGISTRY); Registry<Biome> registry = RegistryAccess.builtin().registryOrThrow(Registry.BIOME_REGISTRY);