Advertisement
Scouter456

Untitled

Jul 1st, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.43 KB | None | 0 0
  1. public class SmithingStoneRecipe extends UpgradeRecipe {
  2.  
  3.     final Ingredient base;
  4.     final Ingredient addition;
  5.     final ItemStack result;
  6.     private final ResourceLocation id;
  7.  
  8.  
  9.     public SmithingStoneRecipe(ResourceLocation pId, Ingredient pBase, Ingredient pAddition, ItemStack pResult) {
  10.         super(pId, pBase, pAddition, pResult);
  11.         this.base = pBase;
  12.         this.addition = pAddition;
  13.         this.result = pResult;
  14.         this.id = pId;
  15.     }
  16.  
  17.     public static void addAttributes(ItemAttributeModifierEvent event){
  18.         ItemStack itemStack = event.getItemStack();
  19.         if(!itemStack.hasTag()) return;
  20.         if(itemStack.getTag().contains("smithing_stone_speed_mod")){
  21.             int addExtraSpeed = event.getItemStack().getTag().getInt("smithing_stone_speed_mod");
  22.             AttributeModifier speedModifier = new AttributeModifier(UUID.randomUUID(), "speed mod", addExtraSpeed, AttributeModifier.Operation.ADDITION);
  23.             event.addModifier(Attributes.ATTACK_SPEED, speedModifier);
  24.         }
  25.  
  26.     }
  27.     @Override
  28.     public ItemStack assemble(Container pInv) {
  29.         ItemStack itemstack = this.result.copy();
  30.         CompoundTag compoundtag = pInv.getItem(0).getTag();
  31.  
  32.         if(addition.test(Items.STONE.getDefaultInstance())){
  33.             //CompoundTag speedTag = pInv.getItem(0).getOrCreateTag();
  34.             //if(speedTag.contains("smithing_stone_speed_mod")){
  35.             //    int currentSpeed = speedTag.getInt("smithing_stone_speed_mod");
  36.             //    speedTag.putInt("smithing_stone_speed_mod", currentSpeed + 1);
  37.             //} else {
  38.             //    speedTag.putInt("smithing_stone_speed_mod", 1);
  39.             //}
  40.             //itemstack.setTag(speedTag.copy());
  41.             double attributeC = pInv.getItem(0).getAttributeModifiers(EquipmentSlot.MAINHAND).get(Attributes.ATTACK_SPEED).stream().toList().get(0).getAmount();
  42.             AttributeModifier speedModifier = new AttributeModifier(UUID.randomUUID(), "speed mod", attributeC + 1, AttributeModifier.Operation.ADDITION);
  43.             itemstack.addAttributeModifier(Attributes.ATTACK_SPEED, speedModifier, EquipmentSlot.MAINHAND);
  44.         }
  45.        
  46.         return itemstack;
  47.     }
  48.  
  49.     public static class Serializer implements RecipeSerializer<SmithingStoneRecipe> {
  50.         public SmithingStoneRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
  51.             Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "base"));
  52.             Ingredient ingredient1 = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "addition"));
  53.             ItemStack itemstack = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(pJson, "result"));
  54.             return new SmithingStoneRecipe(pRecipeId, ingredient, ingredient1, itemstack);
  55.         }
  56.  
  57.         public SmithingStoneRecipe fromNetwork(ResourceLocation pRecipeId, FriendlyByteBuf pBuffer) {
  58.             Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
  59.             Ingredient ingredient1 = Ingredient.fromNetwork(pBuffer);
  60.             ItemStack itemstack = pBuffer.readItem();
  61.             return new SmithingStoneRecipe(pRecipeId, ingredient, ingredient1, itemstack);
  62.         }
  63.  
  64.         public void toNetwork(FriendlyByteBuf pBuffer, SmithingStoneRecipe pRecipe) {
  65.             pRecipe.base.toNetwork(pBuffer);
  66.             pRecipe.addition.toNetwork(pBuffer);
  67.             pBuffer.writeItem(pRecipe.result);
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement