Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SmithingStoneRecipe extends UpgradeRecipe {
- final Ingredient base;
- final Ingredient addition;
- final ItemStack result;
- private final ResourceLocation id;
- public SmithingStoneRecipe(ResourceLocation pId, Ingredient pBase, Ingredient pAddition, ItemStack pResult) {
- super(pId, pBase, pAddition, pResult);
- this.base = pBase;
- this.addition = pAddition;
- this.result = pResult;
- this.id = pId;
- }
- public static void addAttributes(ItemAttributeModifierEvent event){
- ItemStack itemStack = event.getItemStack();
- if(!itemStack.hasTag()) return;
- if(itemStack.getTag().contains("smithing_stone_speed_mod")){
- int addExtraSpeed = event.getItemStack().getTag().getInt("smithing_stone_speed_mod");
- AttributeModifier speedModifier = new AttributeModifier(UUID.randomUUID(), "speed mod", addExtraSpeed, AttributeModifier.Operation.ADDITION);
- event.addModifier(Attributes.ATTACK_SPEED, speedModifier);
- }
- }
- @Override
- public ItemStack assemble(Container pInv) {
- ItemStack itemstack = this.result.copy();
- CompoundTag compoundtag = pInv.getItem(0).getTag();
- if(addition.test(Items.STONE.getDefaultInstance())){
- //CompoundTag speedTag = pInv.getItem(0).getOrCreateTag();
- //if(speedTag.contains("smithing_stone_speed_mod")){
- // int currentSpeed = speedTag.getInt("smithing_stone_speed_mod");
- // speedTag.putInt("smithing_stone_speed_mod", currentSpeed + 1);
- //} else {
- // speedTag.putInt("smithing_stone_speed_mod", 1);
- //}
- //itemstack.setTag(speedTag.copy());
- double attributeC = pInv.getItem(0).getAttributeModifiers(EquipmentSlot.MAINHAND).get(Attributes.ATTACK_SPEED).stream().toList().get(0).getAmount();
- AttributeModifier speedModifier = new AttributeModifier(UUID.randomUUID(), "speed mod", attributeC + 1, AttributeModifier.Operation.ADDITION);
- itemstack.addAttributeModifier(Attributes.ATTACK_SPEED, speedModifier, EquipmentSlot.MAINHAND);
- }
- return itemstack;
- }
- public static class Serializer implements RecipeSerializer<SmithingStoneRecipe> {
- public SmithingStoneRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
- Ingredient ingredient = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "base"));
- Ingredient ingredient1 = Ingredient.fromJson(GsonHelper.getAsJsonObject(pJson, "addition"));
- ItemStack itemstack = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(pJson, "result"));
- return new SmithingStoneRecipe(pRecipeId, ingredient, ingredient1, itemstack);
- }
- public SmithingStoneRecipe fromNetwork(ResourceLocation pRecipeId, FriendlyByteBuf pBuffer) {
- Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
- Ingredient ingredient1 = Ingredient.fromNetwork(pBuffer);
- ItemStack itemstack = pBuffer.readItem();
- return new SmithingStoneRecipe(pRecipeId, ingredient, ingredient1, itemstack);
- }
- public void toNetwork(FriendlyByteBuf pBuffer, SmithingStoneRecipe pRecipe) {
- pRecipe.base.toNetwork(pBuffer);
- pRecipe.addition.toNetwork(pBuffer);
- pBuffer.writeItem(pRecipe.result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement