Update to 1.16.1

This commit is contained in:
Marcel Konrad
2020-07-01 23:44:51 +02:00
parent 8918475788
commit cdc222b1e7
91 changed files with 1887 additions and 2054 deletions

View File

@@ -1,32 +1,31 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries;
@OnlyIn(Dist.CLIENT)
public abstract class ComponentAttribute implements IBuilderComponent
{
protected Map<EnumAttributes, Double> attributes = new HashMap<EnumAttributes, Double>();
protected Function<EnumAttributes, Boolean> applyable;
{
public static final List<Attribute> ATTRIBUTES = ForgeRegistries.ATTRIBUTES.getValues().stream().filter(attribute -> !attribute.func_233754_c_().equals(I18n.format(attribute.func_233754_c_()))).collect(Collectors.toList());
public ComponentAttribute(Function<EnumAttributes, Boolean> applyable)
{
this.applyable = applyable;
}
protected Map<Attribute, Double> attributes = new HashMap<Attribute, Double>();
public void set(EnumAttributes attribute, double ammount)
public void set(Attribute attribute, double ammount)
{
this.attributes.put(attribute, ammount);
}
public double getAmmount(EnumAttributes attribute)
public double getAmmount(Attribute attribute)
{
if(this.attributes.containsKey(attribute))
{
@@ -36,12 +35,12 @@ public abstract class ComponentAttribute implements IBuilderComponent
return 0;
}
public void remove(EnumAttributes attribute)
public void remove(Attribute attribute)
{
this.attributes.remove(attribute);
}
public Set<EnumAttributes> getAttributes()
public Set<Attribute> getAttributes()
{
return this.attributes.keySet();
}

View File

@@ -2,13 +2,12 @@ package exopandora.worldhandler.builder.component.impl;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.function.Function;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import net.minecraft.nbt.INBT;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -16,29 +15,23 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class ComponentAttributeItem extends ComponentAttribute
{
public ComponentAttributeItem(Function<EnumAttributes, Boolean> applyable)
{
super(applyable);
}
@Override
@Nullable
public INBT serialize()
{
ListNBT attributes = new ListNBT();
for(Entry<EnumAttributes, Double> entry : this.attributes.entrySet())
for(Entry<Attribute, Double> entry : this.attributes.entrySet())
{
if(this.applyable.apply(entry.getKey()) && entry.getValue() != 0)
if(entry.getValue() != 0)
{
CompoundNBT attribute = new CompoundNBT();
String id = entry.getKey().getRegistryName().toString();
attribute.putString("AttributeName", entry.getKey().getAttribute());
attribute.putString("Name", entry.getKey().getAttribute());
attribute.putDouble("Amount", entry.getKey().calculate(entry.getValue()));
attribute.putInt("Operation", entry.getKey().getOperation().ordinal());
attribute.putLong("UUIDLeast", UUID.nameUUIDFromBytes(entry.getKey().getAttribute().getBytes()).getLeastSignificantBits());
attribute.putLong("UUIDMost", UUID.nameUUIDFromBytes(entry.getKey().getAttribute().getBytes()).getMostSignificantBits());
attribute.putString("AttributeName", id);
attribute.putDouble("Amount", entry.getValue() / 100);
attribute.putInt("Operation", 1); // 0 = additive, 1 = percentage
attribute.putUniqueId("UUID", UUID.nameUUIDFromBytes(id.getBytes()));
attributes.add(attribute);
}

View File

@@ -1,11 +1,10 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.Map.Entry;
import java.util.function.Function;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT;
@@ -15,25 +14,21 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class ComponentAttributeMob extends ComponentAttribute
{
public ComponentAttributeMob(Function<EnumAttributes, Boolean> applyable)
{
super(applyable);
}
@Override
@Nullable
public INBT serialize()
{
ListNBT attributes = new ListNBT();
for(Entry<EnumAttributes, Double> entry : this.attributes.entrySet())
for(Entry<Attribute, Double> entry : this.attributes.entrySet())
{
if(this.applyable.apply(entry.getKey()) && entry.getValue() != 0)
if(entry.getValue() != 0)
{
CompoundNBT attribute = new CompoundNBT();
String id = entry.getKey().getRegistryName().toString();
attribute.putString("Name", entry.getKey().getAttribute());
attribute.putDouble("Base", entry.getKey().calculate(entry.getValue()));
attribute.putString("Name", id);
attribute.putDouble("Base", entry.getValue() / 100);
attributes.add(attribute);
}

View File

@@ -14,7 +14,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public class ComponentDisplay implements IBuilderComponent
{
private MutableStringTextComponent name = new MutableStringTextComponent();
private String[] lore = new String[2];
private ITextComponent[] lore = new ITextComponent[2];
@Override
public INBT serialize()
@@ -30,9 +30,9 @@ public class ComponentDisplay implements IBuilderComponent
for(int x = 0; x < this.lore.length; x++)
{
if(this.lore[x] != null && !this.lore[x].isEmpty())
if(this.lore[x] != null && !this.lore[x].getString().isEmpty())
{
lore.add(StringNBT.valueOf(this.lore[x]));
lore.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(this.lore[x])));
}
}
@@ -59,32 +59,32 @@ public class ComponentDisplay implements IBuilderComponent
return this.name;
}
public void setLore(String[] lore)
public void setLore(ITextComponent[] lore)
{
this.lore = lore;
}
public String[] getLore()
public ITextComponent[] getLore()
{
return this.lore;
}
public void setLore1(String lore)
public void setLore1(ITextComponent lore)
{
this.lore[0] = lore;
}
public String getLore1()
public ITextComponent getLore1()
{
return this.lore[0];
}
public void setLore2(String lore)
public void setLore2(ITextComponent lore)
{
this.lore[1] = lore;
}
public String getLore2()
public ITextComponent getLore2()
{
return this.lore[1];
}

View File

@@ -9,14 +9,14 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
import exopandora.worldhandler.util.MutableStringTextComponent;
import exopandora.worldhandler.util.NBTHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.nbt.ByteNBT;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
@@ -37,11 +37,11 @@ public class EntityNBT implements IBuilderComponent
private boolean isBaby;
private BlockState blockState;
private ComponentCustom entity = new ComponentCustom();
private ComponentAttributeMob attribute = new ComponentAttributeMob(attribute -> attribute.getApplyable().equals(Applyable.BOTH) || attribute.getApplyable().equals(Applyable.MOB));
private ComponentAttributeMob attribute = new ComponentAttributeMob();
private MutableStringTextComponent customName = new MutableStringTextComponent();
private List<EntityNBT> passengers = new ArrayList<EntityNBT>();
private ResourceLocation[] armorItems = {Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName()};
private ResourceLocation[] handItems = {Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName()};
private ResourceLocation[] armorItems = {Items.AIR.getRegistryName(), Items.AIR.getRegistryName(), Items.AIR.getRegistryName(), Items.AIR.getRegistryName()};
private ResourceLocation[] handItems = {Items.AIR.getRegistryName(), Items.AIR.getRegistryName()};
private ComponentPotionMob potion = new ComponentPotionMob();
public EntityNBT()
@@ -64,22 +64,22 @@ public class EntityNBT implements IBuilderComponent
return this.id;
}
public void setAttribute(EnumAttributes attribute, double ammount)
public void setAttribute(Attribute attribute, double ammount)
{
this.attribute.set(attribute, ammount);
}
public void removeAttribute(EnumAttributes attribute)
public void removeAttribute(Attribute attribute)
{
this.attribute.remove(attribute);
}
public double getAttributeAmmount(EnumAttributes attribute)
public double getAttributeAmmount(Attribute attribute)
{
return this.attribute.getAmmount(attribute);
}
public Set<EnumAttributes> getAttributes()
public Set<Attribute> getAttributes()
{
return this.attribute.getAttributes();
}
@@ -173,7 +173,7 @@ public class EntityNBT implements IBuilderComponent
public void setArmorItem(int index, ResourceLocation location)
{
if(EntityNBT.isArrayIndexValid(this.armorItems, index) && location != null)
if(EntityNBT.isArrayIndexValid(this.armorItems, index) && location != null) //TODO
{
this.armorItems[index] = location;
}

View File

@@ -5,10 +5,11 @@ import java.util.Set;
import exopandora.worldhandler.builder.component.impl.ComponentAttributeItem;
import exopandora.worldhandler.builder.component.impl.ComponentDisplay;
import exopandora.worldhandler.builder.component.impl.ComponentEnchantment;
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
import exopandora.worldhandler.util.MutableStringTextComponent;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -27,7 +28,7 @@ public class BuilderCustomItem extends BuilderGive
public BuilderCustomItem(String player, ResourceLocation item)
{
super(player, item);
this.attribute = this.registerNBTComponent(new ComponentAttributeItem(attribute -> attribute.getApplyable().equals(Applyable.BOTH) || attribute.getApplyable().equals(Applyable.PLAYER)));
this.attribute = this.registerNBTComponent(new ComponentAttributeItem());
this.display = this.registerNBTComponent(new ComponentDisplay());
this.enchantment = this.registerNBTComponent(new ComponentEnchantment());
}
@@ -47,22 +48,22 @@ public class BuilderCustomItem extends BuilderGive
return this.enchantment.getEnchantments();
}
public void setAttribute(EnumAttributes attribute, double ammount)
public void setAttribute(Attribute attribute, double ammount)
{
this.attribute.set(attribute, ammount);
}
public void removeAttribute(EnumAttributes attribute)
public void removeAttribute(Attribute attribute)
{
this.attribute.remove(attribute);
}
public double getAttributeAmmount(EnumAttributes attribute)
public double getAttributeAmmount(Attribute attribute)
{
return this.attribute.getAmmount(attribute);
}
public Set<EnumAttributes> getAttributes()
public Set<Attribute> getAttributes()
{
return this.attribute.getAttributes();
}
@@ -77,22 +78,22 @@ public class BuilderCustomItem extends BuilderGive
return this.display.getName();
}
public void setLore1(String lore)
public void setLore1(ITextComponent lore)
{
this.display.setLore1(lore);
}
public String getLore1()
public ITextComponent getLore1()
{
return this.display.getLore1();
}
public void setLore2(String lore)
public void setLore2(ITextComponent lore)
{
this.display.setLore2(lore);
}
public String getLore2()
public ITextComponent getLore2()
{
return this.display.getLore2();
}

View File

@@ -5,7 +5,7 @@ import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateInt;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.IProperty;
import net.minecraft.state.Property;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist;
@@ -39,7 +39,7 @@ public class BuilderSetBlock extends BuilderBlockPos
this.setMode(mode);
}
public <T extends Comparable<T>> void setState(IProperty<T> property, T value)
public <T extends Comparable<T>> void setState(Property<T> property, T value)
{
this.blockResourceLocation.setProperty(property, value);
this.setBlock(this.blockResourceLocation);

View File

@@ -20,6 +20,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.merchant.villager.VillagerProfession;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
@@ -107,22 +108,22 @@ public class BuilderSummon extends CommandBuilderNBT
return this.nbt.getId();
}
public void setAttribute(EnumAttributes attribute, double ammount)
public void setAttribute(Attribute attribute, double ammount)
{
this.nbt.setAttribute(attribute, ammount);
}
public void removeAttribute(EnumAttributes attribute)
public void removeAttribute(Attribute attribute)
{
this.nbt.removeAttribute(attribute);
}
public double getAttributeAmmount(EnumAttributes attribute)
public double getAttributeAmmount(Attribute attribute)
{
return this.nbt.getAttributeAmmount(attribute);
}
public Set<EnumAttributes> getAttributes()
public Set<Attribute> getAttributes()
{
return this.nbt.getAttributes();
}
@@ -491,7 +492,7 @@ public class BuilderSummon extends CommandBuilderNBT
}
else if(entity.equalsIgnoreCase("Pigman") || entity.equalsIgnoreCase("ZombiePig") || entity.equalsIgnoreCase("ZombiePigman"))
{
return EntityType.ZOMBIE_PIGMAN.getRegistryName();
return EntityType.field_233592_ba_.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wither"))
{

View File

@@ -1,106 +0,0 @@
package exopandora.worldhandler.builder.impl;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public enum EnumAttributes
{
MAX_HEALTH("generic.maxHealth", EnumOperation.ADDITIVE, Applyable.BOTH),
FOLLOW_RANGE("generic.followRange", EnumOperation.ADDITIVE, Applyable.MOB),
KNOCKBACK_RESISTANCE("generic.knockbackResistance", EnumOperation.PERCENTAGE, Applyable.BOTH),
MOVEMENT_SPEED("generic.movementSpeed", EnumOperation.PERCENTAGE, Applyable.BOTH),
ATTACK_DAMAGE("generic.attackDamage", EnumOperation.ADDITIVE, Applyable.BOTH),
ARMOR("generic.armor", EnumOperation.ADDITIVE, Applyable.BOTH),
ARMOR_TOUGHNESS("generic.armorToughness", EnumOperation.ADDITIVE, Applyable.BOTH),
ATTACK_SPEED("generic.attackSpeed", EnumOperation.PERCENTAGE, Applyable.BOTH),
LUCK("generic.luck", EnumOperation.PERCENTAGE, Applyable.PLAYER),
HORSE_JUMP_STRENGTH("horse.jumpStrength", EnumOperation.PERCENTAGE, Applyable.MOB),
ZOMBIE_SPAWN_REINFORCEMENTS("zombie.spawnReinforcements", EnumOperation.PERCENTAGE, Applyable.MOB);
private String attribute;
private EnumOperation operation;
private Applyable applyable;
@OnlyIn(Dist.CLIENT)
public static enum Applyable
{
BOTH,
PLAYER,
MOB
}
private EnumAttributes(String attribute, EnumOperation operation, Applyable applyable)
{
this.attribute = attribute;
this.operation = operation;
this.applyable = applyable;
}
public String getAttribute()
{
return this.attribute;
}
public String getTranslationKey()
{
return "attribute.name." + this.attribute;
}
public String getTranslation()
{
return I18n.format(this.getTranslationKey(), new Object[0]);
}
public EnumOperation getOperation()
{
return this.operation;
}
public Applyable getApplyable()
{
return this.applyable;
}
public double calculate(Double value)
{
return this.operation.getOperation().apply(value);
}
@OnlyIn(Dist.CLIENT)
public static enum EnumOperation
{
ADDITIVE(value -> value, "(+)"),
PERCENTAGE(value -> value / 100, "%");
private final Function<Double, Double> operation;
private final String declaration;
private EnumOperation(Function<Double, Double> operation, String declaration)
{
this.operation = operation;
this.declaration = declaration;
}
public Function<Double, Double> getOperation()
{
return this.operation;
}
public String getDeclaration()
{
return this.declaration;
}
}
public static List<EnumAttributes> getAttributesFor(Applyable applyable)
{
return Arrays.stream(EnumAttributes.values()).filter(attribute -> attribute.getApplyable().equals(applyable)).collect(Collectors.toList());
}
}

View File

@@ -8,7 +8,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.command.arguments.BlockStateParser;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.IProperty;
import net.minecraft.state.Property;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -70,9 +70,9 @@ public class BlockResourceLocation extends ItemResourceLocation
return this.state;
}
public <T extends Comparable<T>> void setProperty(IProperty<T> property, T value)
public <T extends Comparable<T>> void setProperty(Property<T> property, T value)
{
if(this.state != null && this.state.has(property))
if(this.state != null && this.state.func_235901_b_(property)) //has
{
this.state = this.state.with(property, value);
}