Renamed EffectData to EffectNBT, Implemented INBTWritable for EffectNBT
This commit is contained in:
@@ -18,7 +18,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
|||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public abstract class ComponentPotion implements IBuilderComponent
|
public abstract class ComponentPotion implements IBuilderComponent
|
||||||
{
|
{
|
||||||
protected final Map<Effect, EffectData> potions = new HashMap<Effect, EffectData>();
|
protected final Map<Effect, EffectNBT> potions = new HashMap<Effect, EffectNBT>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -26,20 +26,14 @@ public abstract class ComponentPotion implements IBuilderComponent
|
|||||||
{
|
{
|
||||||
ListNBT list = new ListNBT();
|
ListNBT list = new ListNBT();
|
||||||
|
|
||||||
for(Entry<Effect, EffectData> entry : this.potions.entrySet())
|
for(Entry<Effect, EffectNBT> entry : this.potions.entrySet())
|
||||||
{
|
{
|
||||||
EffectData potion = entry.getValue();
|
EffectNBT effect = entry.getValue();
|
||||||
|
|
||||||
if(potion.getAmplifier() > 0)
|
if(effect.getAmplifier() > 0)
|
||||||
{
|
{
|
||||||
CompoundNBT compound = new CompoundNBT();
|
CompoundNBT compound = effect.serialize();
|
||||||
|
|
||||||
compound.putByte("Id", (byte) Effect.getId(entry.getKey()));
|
compound.putByte("Id", (byte) Effect.getId(entry.getKey()));
|
||||||
compound.putByte("Amplifier", (byte) (potion.getAmplifier() - 1));
|
|
||||||
compound.putInt("Duration", Math.min(potion.toTicks(), 1000000));
|
|
||||||
compound.putBoolean("Ambient", potion.getAmbient());
|
|
||||||
compound.putBoolean("ShowParticles", potion.getShowParticles());
|
|
||||||
|
|
||||||
list.add(compound);
|
list.add(compound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,7 +106,7 @@ public abstract class ComponentPotion implements IBuilderComponent
|
|||||||
return this.getMetadata(potion).getAmbient();
|
return this.getMetadata(potion).getAmbient();
|
||||||
}
|
}
|
||||||
|
|
||||||
private EffectData getMetadata(Effect potion)
|
private EffectNBT getMetadata(Effect potion)
|
||||||
{
|
{
|
||||||
return this.potions.get(this.validate(potion));
|
return this.potions.get(this.validate(potion));
|
||||||
}
|
}
|
||||||
@@ -121,7 +115,7 @@ public abstract class ComponentPotion implements IBuilderComponent
|
|||||||
{
|
{
|
||||||
if(!this.potions.containsKey(potion))
|
if(!this.potions.containsKey(potion))
|
||||||
{
|
{
|
||||||
this.potions.put(potion, new EffectData());
|
this.potions.put(potion, new EffectNBT());
|
||||||
}
|
}
|
||||||
|
|
||||||
return potion;
|
return potion;
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package exopandora.worldhandler.builder.component.impl;
|
package exopandora.worldhandler.builder.component.impl;
|
||||||
|
|
||||||
|
import exopandora.worldhandler.builder.INBTWritable;
|
||||||
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public class EffectData
|
public class EffectNBT implements INBTWritable
|
||||||
{
|
{
|
||||||
private byte amplifier;
|
private byte amplifier;
|
||||||
private int seconds;
|
private int seconds;
|
||||||
@@ -13,12 +15,12 @@ public class EffectData
|
|||||||
private boolean showParticles;
|
private boolean showParticles;
|
||||||
private boolean ambient;
|
private boolean ambient;
|
||||||
|
|
||||||
public EffectData()
|
public EffectNBT()
|
||||||
{
|
{
|
||||||
this((byte) 0, 0, 0, 0, true, false);
|
this((byte) 0, 0, 0, 0, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData(byte amplifier, int seconds, int minutes, int hours, boolean showParticles, boolean ambient)
|
public EffectNBT(byte amplifier, int seconds, int minutes, int hours, boolean showParticles, boolean ambient)
|
||||||
{
|
{
|
||||||
this.amplifier = amplifier;
|
this.amplifier = amplifier;
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
@@ -90,12 +92,25 @@ public class EffectData
|
|||||||
|
|
||||||
public int toTicks()
|
public int toTicks()
|
||||||
{
|
{
|
||||||
return EffectData.toTicks(this.seconds, this.minutes, this.hours);
|
return EffectNBT.toTicks(this.seconds, this.minutes, this.hours);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int toSeconds()
|
public int toSeconds()
|
||||||
{
|
{
|
||||||
return EffectData.toSeconds(this.seconds, this.minutes, this.hours);
|
return EffectNBT.toSeconds(this.seconds, this.minutes, this.hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundNBT serialize()
|
||||||
|
{
|
||||||
|
CompoundNBT compound = new CompoundNBT();
|
||||||
|
|
||||||
|
compound.putByte("Amplifier", (byte) (this.amplifier - 1));
|
||||||
|
compound.putInt("Duration", Math.min(this.toTicks(), 1000000));
|
||||||
|
compound.putBoolean("Ambient", this.ambient);
|
||||||
|
compound.putBoolean("ShowParticles", this.showParticles);
|
||||||
|
|
||||||
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int toTicks(int seconds, int minutes, int hours)
|
public static int toTicks(int seconds, int minutes, int hours)
|
||||||
@@ -108,37 +123,37 @@ public class EffectData
|
|||||||
return seconds + minutes * 60 + hours * 3600;
|
return seconds + minutes * 60 + hours * 3600;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData withAmplifier(byte amplifier)
|
public EffectNBT withAmplifier(byte amplifier)
|
||||||
{
|
{
|
||||||
this.amplifier = amplifier;
|
this.amplifier = amplifier;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData withShowParticles(boolean showParticles)
|
public EffectNBT withShowParticles(boolean showParticles)
|
||||||
{
|
{
|
||||||
this.showParticles = showParticles;
|
this.showParticles = showParticles;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData withSeconds(int seconds)
|
public EffectNBT withSeconds(int seconds)
|
||||||
{
|
{
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData withMinutes(int minutes)
|
public EffectNBT withMinutes(int minutes)
|
||||||
{
|
{
|
||||||
this.minutes = minutes;
|
this.minutes = minutes;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData withHours(int hours)
|
public EffectNBT withHours(int hours)
|
||||||
{
|
{
|
||||||
this.hours = hours;
|
this.hours = hours;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EffectData withAmbient(boolean ambient)
|
public EffectNBT withAmbient(boolean ambient)
|
||||||
{
|
{
|
||||||
this.ambient = ambient;
|
this.ambient = ambient;
|
||||||
return this;
|
return this;
|
||||||
@@ -147,7 +162,7 @@ public class EffectData
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "EffectData [amplifier=" + amplifier + ", seconds=" + seconds + ", minutes=" + minutes + ", hours=" + hours + ", showParticles=" + showParticles + ", ambient=" + ambient + "]";
|
return "EffectNBT [amplifier=" + amplifier + ", seconds=" + seconds + ", minutes=" + minutes + ", hours=" + hours + ", showParticles=" + showParticles + ", ambient=" + ambient + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import exopandora.worldhandler.builder.CommandBuilder;
|
import exopandora.worldhandler.builder.CommandBuilder;
|
||||||
import exopandora.worldhandler.builder.CommandSyntax;
|
import exopandora.worldhandler.builder.CommandSyntax;
|
||||||
import exopandora.worldhandler.builder.component.impl.EffectData;
|
import exopandora.worldhandler.builder.component.impl.EffectNBT;
|
||||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||||
import net.minecraft.potion.Effect;
|
import net.minecraft.potion.Effect;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
@@ -123,7 +123,7 @@ public class BuilderPotionEffect extends CommandBuilder
|
|||||||
public void setSeconds(int seconds)
|
public void setSeconds(int seconds)
|
||||||
{
|
{
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
this.setDuration(EffectData.toSeconds(this.seconds, this.minutes, this.hours));
|
this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinutes()
|
public int getMinutes()
|
||||||
@@ -134,7 +134,7 @@ public class BuilderPotionEffect extends CommandBuilder
|
|||||||
public void setMinutes(int minutes)
|
public void setMinutes(int minutes)
|
||||||
{
|
{
|
||||||
this.minutes = minutes;
|
this.minutes = minutes;
|
||||||
this.setDuration(EffectData.toSeconds(this.seconds, this.minutes, this.hours));
|
this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHours()
|
public int getHours()
|
||||||
@@ -145,7 +145,7 @@ public class BuilderPotionEffect extends CommandBuilder
|
|||||||
public void setHours(int hours)
|
public void setHours(int hours)
|
||||||
{
|
{
|
||||||
this.hours = hours;
|
this.hours = hours;
|
||||||
this.setDuration(EffectData.toSeconds(this.seconds, this.minutes, this.hours));
|
this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderGeneric getGiveCommand()
|
public BuilderGeneric getGiveCommand()
|
||||||
|
|||||||
Reference in New Issue
Block a user