Move block, item, potion and enchantment registries over to the @ObjectHolder system and reorganise the potion classes a bit

This commit is contained in:
Electroblob77
2019-01-05 22:59:45 +00:00
parent eb2abdfbe9
commit 212fbe51df
8 changed files with 474 additions and 420 deletions
@@ -3,10 +3,10 @@ package electroblob.wizardry.potion;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.client.DrawingUtils;
import electroblob.wizardry.constants.Constants;
import electroblob.wizardry.entity.construct.EntityDecay;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
@@ -21,12 +21,10 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@Mod.EventBusSubscriber
public class PotionDecay extends Potion {
private static final ResourceLocation ICON = new ResourceLocation(Wizardry.MODID, "textures/gui/decay_icon.png");
public class PotionDecay extends PotionMagicEffect {
public PotionDecay(boolean isBadEffect, int liquidColour){
super(isBadEffect, liquidColour);
super(isBadEffect, liquidColour, new ResourceLocation(Wizardry.MODID, "textures/gui/potion_icon_decay.png"));
// This needs to be here because registerPotionAttributeModifier doesn't like it if the potion has no name yet.
this.setPotionName("potion." + Wizardry.MODID + ":decay");
this.registerPotionAttributeModifier(SharedMonsterAttributes.MOVEMENT_SPEED,
@@ -46,20 +44,6 @@ public class PotionDecay extends Potion {
target.attackEntityFrom(DamageSource.WITHER, 1);
}
@Override
@SideOnly(Side.CLIENT)
public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc){
mc.renderEngine.bindTexture(ICON);
WizardryUtilities.drawTexturedRect(x + 6, y + 7, 0, 0, 18, 18, 18, 18);
}
@Override
@SideOnly(Side.CLIENT)
public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha){
mc.renderEngine.bindTexture(ICON);
WizardryUtilities.drawTexturedRect(x + 3, y + 3, 0, 0, 18, 18, 18, 18);
}
@SubscribeEvent
public static void onLivingUpdateEvent(LivingUpdateEvent event){
@@ -1,14 +1,13 @@
package electroblob.wizardry.potion;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.client.DrawingUtils;
import electroblob.wizardry.constants.Constants;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
@@ -19,12 +18,10 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@Mod.EventBusSubscriber
public class PotionFrost extends Potion implements ICustomPotionParticles {
private static final ResourceLocation ICON = new ResourceLocation(Wizardry.MODID, "textures/gui/frost_icon.png");
public class PotionFrost extends PotionMagicEffect implements ICustomPotionParticles {
public PotionFrost(boolean isBadEffect, int liquidColour){
super(isBadEffect, liquidColour);
super(isBadEffect, liquidColour, new ResourceLocation(Wizardry.MODID, "textures/gui/potion_icon_frost.png"));
// This needs to be here because registerPotionAttributeModifier doesn't like it if the potion has no name yet.
this.setPotionName("potion." + Wizardry.MODID + ":frost");
// With -0.5 as the 'amount', frost 1 slows the entity down by a half and frost 2 roots it to the spot
@@ -33,27 +30,8 @@ public class PotionFrost extends Potion implements ICustomPotionParticles {
// More UUIDs: 85602e0b-4801-4a87-94f3-bf617c97014e
}
@Override
public void performEffect(EntityLivingBase entitylivingbase, int strength){
// Nothing here because this potion works on attribute modifiers.
}
@Override
public void spawnCustomParticle(World world, double x, double y, double z){
}
@Override
@SideOnly(Side.CLIENT)
public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc){
mc.renderEngine.bindTexture(ICON);
WizardryUtilities.drawTexturedRect(x + 6, y + 7, 0, 0, 18, 18, 18, 18);
}
@Override
@SideOnly(Side.CLIENT)
public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha){
mc.renderEngine.bindTexture(ICON);
WizardryUtilities.drawTexturedRect(x + 3, y + 3, 0, 0, 18, 18, 18, 18);
ParticleBuilder.create(Type.SNOW).pos(x, y, z).time(15 + world.rand.nextInt(5)).spawn(world);
}
@@ -1,7 +1,6 @@
package electroblob.wizardry.potion;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.util.WizardryUtilities;
import electroblob.wizardry.client.DrawingUtils;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
@@ -9,15 +8,17 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/** Class for all potions that work on events only. */
/**
* As of Wizardry 4.2, this class is used by all of wizardry's potions. Potions that work solely on events
* instantiate this class directly, all other potions extend it.
*/
public class PotionMagicEffect extends Potion {
private static final ResourceLocation ICONS = new ResourceLocation(Wizardry.MODID, "textures/gui/potion_icons.png");
private final int textureIndex;
private final ResourceLocation texture;
public PotionMagicEffect(boolean isBadEffect, int liquidColour, int textureIndex){
public PotionMagicEffect(boolean isBadEffect, int liquidColour, ResourceLocation texture){
super(isBadEffect, liquidColour);
this.textureIndex = textureIndex;
this.texture = texture;
}
@Override
@@ -28,17 +29,20 @@ public class PotionMagicEffect extends Potion {
@Override
@SideOnly(Side.CLIENT)
public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc){
mc.renderEngine.bindTexture(ICONS);
WizardryUtilities.drawTexturedRect(x + 6, y + 7, 18 * (textureIndex % 4), 18 * (textureIndex / 4), 18, 18, 72,
72);
drawIcon(x + 6, y + 7, effect, mc);
}
@Override
@SideOnly(Side.CLIENT)
public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha){
mc.renderEngine.bindTexture(ICONS);
WizardryUtilities.drawTexturedRect(x + 3, y + 3, 18 * (textureIndex % 4), 18 * (textureIndex / 4), 18, 18, 72,
72);
net.minecraft.client.renderer.GlStateManager.color(1, 1, 1, alpha);
drawIcon(x + 3, y + 3, effect, mc);
}
@SideOnly(Side.CLIENT)
protected void drawIcon(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc){
mc.renderEngine.bindTexture(texture);
DrawingUtils.drawTexturedRect(x, y, 0, 0, 18, 18, 18, 18);
}
}
@@ -1,13 +1,16 @@
package electroblob.wizardry.potion;
import net.minecraft.util.ResourceLocation;
/**
* Same as {@link PotionMagicEffect}, but also implements {@link ICustomPotionParticles} to allow anonymous classes to
* extend it and add their own particles.
* extend it and add their own particles. It is advised that all other (named) classes extend and implement the
* underlying class and interface rather than extending this class.
*/
public abstract class PotionMagicEffectParticles extends PotionMagicEffect implements ICustomPotionParticles {
public PotionMagicEffectParticles(boolean isBadEffect, int liquidColour, int textureIndex){
super(isBadEffect, liquidColour, textureIndex);
public PotionMagicEffectParticles(boolean isBadEffect, int liquidColour, ResourceLocation texture){
super(isBadEffect, liquidColour, texture);
}
}