-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added recipe to apply banners to shields
- Loading branch information
Showing
12 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/insane96mcp/shieldsplus/module/base/feature/BaseFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/insane96mcp/shieldsplus/render/ShieldBlockEntityWithoutLevelRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/insane96mcp/shieldsplus/setup/SPRecipeSerializers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.insane96mcp.shieldsplus.setup; | ||
|
||
import com.insane96mcp.shieldsplus.ShieldsPlus; | ||
import com.insane96mcp.shieldsplus.world.item.crafting.SPShieldDecorationRecipe; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraft.world.item.crafting.SimpleRecipeSerializer; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
public class SPRecipeSerializers { | ||
public static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ShieldsPlus.MOD_ID); | ||
|
||
public static final RegistryObject<SimpleRecipeSerializer<SPShieldDecorationRecipe>> SHIELD_DECORATION_RECIPE = RECIPE_SERIALIZERS.register("shield_decoration_recipe", () -> new SimpleRecipeSerializer<>(SPShieldDecorationRecipe::new)); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/insane96mcp/shieldsplus/setup/SPShieldMaterials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...cp/shieldsplus/item/SPShieldMaterial.java → ...eldsplus/world/item/SPShieldMaterial.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/java/com/insane96mcp/shieldsplus/world/item/crafting/SPShieldDecorationRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.insane96mcp.shieldsplus.world.item.crafting; | ||
|
||
import com.insane96mcp.shieldsplus.setup.SPRecipeSerializers; | ||
import com.insane96mcp.shieldsplus.world.item.SPShieldItem; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.inventory.CraftingContainer; | ||
import net.minecraft.world.item.BannerItem; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.CustomRecipe; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SPShieldDecorationRecipe extends CustomRecipe { | ||
public SPShieldDecorationRecipe(ResourceLocation id) { | ||
super(id); | ||
} | ||
|
||
public boolean matches(CraftingContainer craftingContainer, @NotNull Level level) { | ||
ItemStack shieldStack = ItemStack.EMPTY; | ||
ItemStack bannerStack = ItemStack.EMPTY; | ||
|
||
for(int i = 0; i < craftingContainer.getContainerSize(); ++i) { | ||
ItemStack itemStack = craftingContainer.getItem(i); | ||
if (!itemStack.isEmpty()) { | ||
if (itemStack.getItem() instanceof BannerItem) { | ||
if (!bannerStack.isEmpty()) { | ||
return false; | ||
} | ||
|
||
bannerStack = itemStack; | ||
} | ||
else { | ||
if (!(itemStack.getItem() instanceof SPShieldItem)) { | ||
return false; | ||
} | ||
|
||
if (!shieldStack.isEmpty()) { | ||
return false; | ||
} | ||
|
||
if (BlockItem.getBlockEntityData(itemStack) != null) { | ||
return false; | ||
} | ||
|
||
shieldStack = itemStack; | ||
} | ||
} | ||
} | ||
|
||
return !shieldStack.isEmpty() && !bannerStack.isEmpty(); | ||
} | ||
|
||
public @NotNull ItemStack assemble(CraftingContainer craftingContainer) { | ||
ItemStack bannerStack = ItemStack.EMPTY; | ||
ItemStack shieldStack = ItemStack.EMPTY; | ||
|
||
for(int i = 0; i < craftingContainer.getContainerSize(); ++i) { | ||
ItemStack itemStack = craftingContainer.getItem(i); | ||
if (!itemStack.isEmpty()) { | ||
if (itemStack.getItem() instanceof BannerItem) { | ||
bannerStack = itemStack; | ||
} | ||
else if (itemStack.getItem() instanceof SPShieldItem) { | ||
shieldStack = itemStack.copy(); | ||
} | ||
} | ||
} | ||
|
||
if (!shieldStack.isEmpty()) { | ||
CompoundTag bannerTag = BlockItem.getBlockEntityData(bannerStack); | ||
CompoundTag shieldTag = bannerTag == null ? new CompoundTag() : bannerTag.copy(); | ||
shieldTag.putInt("Base", ((BannerItem) bannerStack.getItem()).getColor().getId()); | ||
BlockItem.setBlockEntityData(shieldStack, BlockEntityType.BANNER, shieldTag); | ||
} | ||
return shieldStack; | ||
} | ||
|
||
public boolean canCraftInDimensions(int width, int height) { | ||
return width * height >= 2; | ||
} | ||
|
||
public @NotNull RecipeSerializer<?> getSerializer() { | ||
return SPRecipeSerializers.SHIELD_DECORATION_RECIPE.get(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/data/shieldsplus/recipes/shield_decoration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "shieldsplus:shield_decoration_recipe" | ||
} |