refactor: Flattened the magic crystal blocks, renamed crystal items

This commit is contained in:
WinDanesz
2022-09-09 22:51:18 +02:00
parent d30a40bdc4
commit b1e70c01f0
80 changed files with 421 additions and 458 deletions
@@ -5,12 +5,7 @@ import electroblob.wizardry.registry.WizardryTabs;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
@@ -18,12 +13,10 @@ import java.util.EnumMap;
public class BlockCrystal extends Block {
public static final PropertyEnum<Element> ELEMENT = PropertyEnum.create("element", Element.class);
private static final EnumMap<Element, MapColor> map_colours = new EnumMap<>(Element.class);
private static final EnumMap<Element, MapColor> map_colours = new EnumMap<>(Element.class);
static {
map_colours.put(Element.MAGIC, MapColor.PINK);
static {
map_colours.put(Element.MAGIC, MapColor.PINK);
map_colours.put(Element.FIRE, MapColor.ORANGE_STAINED_HARDENED_CLAY);
map_colours.put(Element.ICE, MapColor.LIGHT_BLUE);
map_colours.put(Element.LIGHTNING, MapColor.CYAN);
@@ -32,45 +25,19 @@ public class BlockCrystal extends Block {
map_colours.put(Element.SORCERY, MapColor.LIME);
map_colours.put(Element.HEALING, MapColor.YELLOW);
}
public BlockCrystal(Material material){
super(material);
this.setDefaultState(this.blockState.getBaseState().withProperty(ELEMENT, Element.MAGIC));
this.setCreativeTab(WizardryTabs.WIZARDRY);
private final Element element;
public BlockCrystal(Element element) {
super(Material.IRON);
this.setCreativeTab(WizardryTabs.WIZARDRY);
this.setHarvestLevel("pickaxe", 2);
}
@Override
public int damageDropped(IBlockState state){
return (state.getValue(ELEMENT)).ordinal();
}
@Override
public MapColor getMapColor(IBlockState state, IBlockAccess world, BlockPos pos){
return map_colours.get(state.getProperties().get(ELEMENT));
this.element = element;
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items){
if(this.getCreativeTab() == tab){
for(Element element : Element.values()){
items.add(new ItemStack(this, 1, element.ordinal()));
}
}
public MapColor getMapColor(IBlockState state, IBlockAccess world, BlockPos pos) {
return map_colours.get(state.getProperties().get(element));
}
@Override
public IBlockState getStateFromMeta(int metadata){
return this.getDefaultState().withProperty(ELEMENT, Element.values()[metadata]);
}
@Override
public int getMetaFromState(IBlockState state){
return (state.getValue(ELEMENT)).ordinal();
}
@Override
protected BlockStateContainer createBlockState(){
return new BlockStateContainer(this, ELEMENT);
}
}
@@ -40,7 +40,7 @@ public class BlockCrystalOre extends Block {
@Override
public Item getItemDropped(IBlockState state, Random random, int fortune){
return WizardryItems.crystal_magic;
return WizardryItems.magic_crystal;
}
@Override
@@ -51,13 +51,6 @@ public final class WizardryModels {
public static void register(ModelRegistryEvent event){
// ItemBlocks
ModelLoader.setCustomStateMapper(WizardryBlocks.crystal_block, new StateMap.Builder()
.withName(BlockCrystal.ELEMENT).withSuffix("_crystal_block").build());
// Yay unchecked casting! But we know it's always ok here, and it makes everything much neater.
ItemBlockMultiTextured crystalBlockItem = (ItemBlockMultiTextured)Item.getItemFromBlock(WizardryBlocks.crystal_block);
registerMultiTexturedModel(crystalBlockItem);
ModelLoader.setCustomStateMapper(WizardryBlocks.runestone, new StateMap.Builder()
.withName(BlockRunestone.ELEMENT).withSuffix("_runestone").build());
ItemBlockMultiTextured runestoneItem = (ItemBlockMultiTextured)Item.getItemFromBlock(WizardryBlocks.runestone);
@@ -341,7 +341,7 @@ public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntity
int j = 3 + this.rand.nextInt(3) + this.rand.nextInt(1 + lootingLevel);
for(int k = 0; k < j; k++){
this.dropItem(WizardryItems.crystal_magic, 1);
this.dropItem(WizardryItems.magic_crystal, 1);
}
// Evil wizards occasionally drop one of their spells as a spell book, but not magic missile. This isn't in
@@ -506,7 +506,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp
// All wizards will buy spell books
ItemStack anySpellBook = new ItemStack(WizardryItems.spell_book, 1, OreDictionary.WILDCARD_VALUE);
ItemStack crystalStack = new ItemStack(WizardryItems.crystal_magic, 5);
ItemStack crystalStack = new ItemStack(WizardryItems.magic_crystal, 5);
this.trades.add(new MerchantRecipe(anySpellBook, crystalStack));
@@ -576,7 +576,7 @@ public class EntityWizard extends EntityCreature implements INpc, IMerchant, ISp
if(itemToSell.isEmpty()) return;
ItemStack secondItemToBuy = tier == Tier.MASTER ? new ItemStack(WizardryItems.astral_diamond)
: new ItemStack(WizardryItems.crystal_magic, tier.ordinal() * 3 + 1 + rand.nextInt(4));
: new ItemStack(WizardryItems.magic_crystal, tier.ordinal() * 3 + 1 + rand.nextInt(4));
merchantrecipelist.add(new MerchantRecipe(this.getRandomPrice(tier), secondItemToBuy, itemToSell));
}
@@ -97,9 +97,9 @@ public class ArcaneWorkbenchRecipe implements IRecipeWrapper {
int count = MathHelper.ceil((float)mana / Constants.MANA_PER_CRYSTAL);
// A stack of crystals will almost certainly be enough mana, but you never know!
// Using ItemStack.EMPTY to avoid deprecated method; crystals' stack size is not stack-sensitive so it doesn't matter
if(count <= WizardryItems.crystal_magic.getItemStackLimit(ItemStack.EMPTY)){
if(count <= WizardryItems.magic_crystal.getItemStackLimit(ItemStack.EMPTY)){
for (Element element : Element.values()) {
crystalStacks.add(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Wizardry.MODID, "crystal_" + element.name().toLowerCase())), count));
crystalStacks.add(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Wizardry.MODID, element.name().toLowerCase() + "_crystal")), count));
}
}
@@ -144,12 +144,12 @@ public class ImbuementAltarRecipeCategory implements IRecipeCategory<ImbuementAl
List<ImbuementAltarRecipe> recipes = new ArrayList<>();
ItemStack input = new ItemStack(WizardryItems.crystal_magic);
ItemStack input = new ItemStack(WizardryItems.magic_crystal);
for(Element element : Element.values()){
List<List<ItemStack>> dusts = Collections.nCopies(4, Collections.singletonList(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Wizardry.MODID,
"spectral_dust_" + element.name().toLowerCase())))));
ItemStack output = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Wizardry.MODID, "crystal_" + element.name().toLowerCase())));
ItemStack output = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Wizardry.MODID, element.name().toLowerCase() + "_crystal")));
recipes.add(new ImbuementAltarRecipe(input, dusts, output));
}
@@ -161,16 +161,17 @@ public class ImbuementAltarRecipeCategory implements IRecipeCategory<ImbuementAl
List<ImbuementAltarRecipe> recipes = new ArrayList<>();
ItemStack input = new ItemStack(WizardryBlocks.crystal_block);
ItemStack input = new ItemStack(WizardryBlocks.magic_crystal_block);
for(Element element : Element.values()){
if(element == Element.MAGIC) continue;
for (Element element : Element.values()) {
if (element == Element.MAGIC) { continue; }
int meta = element.ordinal();
List<List<ItemStack>> dusts = Collections.nCopies(4, Collections.singletonList(new ItemStack(ForgeRegistries.ITEMS.getValue(
new ResourceLocation(Wizardry.MODID, "spectral_dust_" + element.name().toLowerCase())))));
ItemStack output = new ItemStack(WizardryBlocks.crystal_block, 1, meta);
recipes.add(new ImbuementAltarRecipe(input, dusts, output));
List<List<ItemStack>> dusts = Collections.nCopies(4, Collections.singletonList(new ItemStack(ForgeRegistries.ITEMS.getValue(
new ResourceLocation(Wizardry.MODID, "spectral_dust_" + element.name().toLowerCase())))));
ItemStack output = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Wizardry.MODID, element.getName().toLowerCase()
+ "_crystal_block")));
recipes.add(new ImbuementAltarRecipe(input, dusts, output));
}
return recipes;
@@ -66,7 +66,7 @@ public class WizardryJEIPlugin implements IModPlugin {
}
}
addItemInfo(registry, WizardryItems.crystal_magic);
addItemInfo(registry, WizardryItems.magic_crystal);
addItemInfo(registry, WizardryItems.wizard_handbook);
addItemInfo(registry, WizardryItems.crystal_shard);
addItemInfo(registry, WizardryItems.grand_crystal);
@@ -92,7 +92,7 @@ public class ContainerArcaneWorkbench extends Container implements ISpellSortabl
}
this.addSlotToContainer(new SlotItemList(tileentity, CRYSTAL_SLOT, 13, 101, 64,
WizardryItems.crystal_magic, WizardryItems.crystal_shard, WizardryItems.grand_crystal))
WizardryItems.magic_crystal, WizardryItems.crystal_shard, WizardryItems.grand_crystal))
.setBackgroundName(EMPTY_SLOT_CRYSTAL.toString());
this.addSlotToContainer(new SlotWorkbenchItem(tileentity, CENTRE_SLOT, 80, 64, this));
@@ -40,7 +40,7 @@ public class ItemArcaneTome extends Item {
tooltip.add(tier.getDisplayNameWithFormatting());
Tier tier2 = Tier.values()[tier.ordinal() - 1];
Wizardry.proxy.addMultiLineDescription(tooltip, "item." + Wizardry.MODID + "arcane_tome.desc",
Wizardry.proxy.addMultiLineDescription(tooltip, "item." + Wizardry.MODID + ":arcane_tome.desc",
tier2.getDisplayNameWithFormatting() + "\u00A77", tier.getDisplayNameWithFormatting() + "\u00A77");
}
@@ -1,13 +1,7 @@
package electroblob.wizardry.item;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.registry.WizardryTabs;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
/** Note that in 1.13, <i>the flattening</i> will make this class redundant, much like ItemCoal, which is probably its
* closest analog in vanilla. */
@@ -2,6 +2,7 @@ package electroblob.wizardry.registry;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.block.*;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.tileentity.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@@ -43,7 +44,15 @@ public final class WizardryBlocks {
public static final Block crystal_ore = placeholder();
public static final Block crystal_flower = placeholder();
public static final Block transportation_stone = placeholder();
public static final Block crystal_block = placeholder();
public static final Block magic_crystal_block = placeholder();
public static final Block fire_crystal_block = placeholder();
public static final Block ice_crystal_block = placeholder();
public static final Block lightning_crystal_block = placeholder();
public static final Block necromancy_crystal_block = placeholder();
public static final Block earth_crystal_block = placeholder();
public static final Block sorcery_crystal_block = placeholder();
public static final Block healing_crystal_block = placeholder();
public static final Block petrified_stone = placeholder();
public static final Block ice_statue = placeholder();
@@ -108,7 +117,15 @@ public final class WizardryBlocks {
registerBlock(registry, "crystal_ore", new BlockCrystalOre(Material.ROCK).setHardness(3.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "crystal_flower", new BlockCrystalFlower(Material.PLANTS).setHardness(0.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "transportation_stone", new BlockTransportationStone(Material.ROCK).setHardness(0.3F).setLightLevel(0.5f).setLightOpacity(0).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "crystal_block", new BlockCrystal(Material.IRON).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "magic_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "fire_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "ice_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "lightning_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "necromancy_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "earth_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "sorcery_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "healing_crystal_block", new BlockCrystal(Element.MAGIC).setHardness(5.0F).setResistance(10.0F).setCreativeTab(WizardryTabs.WIZARDRY));
registerBlock(registry, "petrified_stone", new BlockStatue(Material.ROCK).setHardness(1.5F).setResistance(10.0F));
registerBlock(registry, "ice_statue", new BlockStatue(Material.ICE).setHardness(0.5F).setLightOpacity(3));
@@ -80,14 +80,14 @@ public final class WizardryItems {
// point where all the items were listed, but that's not possible within the current system unless you use an array,
// which means you lose the individual fields...
public static final Item crystal_magic = placeholder();
public static final Item crystal_earth = placeholder();
public static final Item crystal_fire = placeholder();
public static final Item crystal_healing = placeholder();
public static final Item crystal_ice = placeholder();
public static final Item crystal_lightning = placeholder();
public static final Item crystal_necromancy = placeholder();
public static final Item crystal_sorcery = placeholder();
public static final Item magic_crystal = placeholder();
public static final Item earth_crystal = placeholder();
public static final Item fire_crystal = placeholder();
public static final Item healing_crystal = placeholder();
public static final Item ice_crystal = placeholder();
public static final Item lightning_crystal = placeholder();
public static final Item necromancy_crystal = placeholder();
public static final Item sorcery_crystal = placeholder();
public static final Item grand_crystal = placeholder();
public static final Item crystal_shard = placeholder();
@@ -560,7 +560,15 @@ public final class WizardryItems {
String[] elements = Arrays.stream(Element.values()).map(Element::getName).toArray(String[]::new);
String[] woodTypes = Arrays.stream(BlockPlanks.EnumType.values()).map(BlockPlanks.EnumType::getName).toArray(String[]::new);
registerMultiTexturedItemBlock(registry, WizardryBlocks.crystal_block, true, elements);
registerItemBlock(registry, WizardryBlocks.magic_crystal_block);
registerItemBlock(registry, WizardryBlocks.fire_crystal_block);
registerItemBlock(registry, WizardryBlocks.ice_crystal_block);
registerItemBlock(registry, WizardryBlocks.lightning_crystal_block);
registerItemBlock(registry, WizardryBlocks.necromancy_crystal_block);
registerItemBlock(registry, WizardryBlocks.earth_crystal_block);
registerItemBlock(registry, WizardryBlocks.sorcery_crystal_block);
registerItemBlock(registry, WizardryBlocks.healing_crystal_block);
registerMultiTexturedItemBlock(registry, WizardryBlocks.runestone, false, elements);
registerMultiTexturedItemBlock(registry, WizardryBlocks.runestone_pedestal, false, elements);
registerMultiTexturedItemBlock(registry, WizardryBlocks.gilded_wood, true, woodTypes);
@@ -584,14 +592,14 @@ public final class WizardryItems {
// Items
registerItem(registry, "crystal_magic", new ItemCrystal());
registerItem(registry, "crystal_earth", new ItemCrystal());
registerItem(registry, "crystal_fire", new ItemCrystal());
registerItem(registry, "crystal_healing", new ItemCrystal());
registerItem(registry, "crystal_ice", new ItemCrystal());
registerItem(registry, "crystal_lightning", new ItemCrystal());
registerItem(registry, "crystal_necromancy", new ItemCrystal());
registerItem(registry, "crystal_sorcery", new ItemCrystal());
registerItem(registry, "magic_crystal", new ItemCrystal());
registerItem(registry, "earth_crystal", new ItemCrystal());
registerItem(registry, "fire_crystal", new ItemCrystal());
registerItem(registry, "healing_crystal", new ItemCrystal());
registerItem(registry, "ice_crystal", new ItemCrystal());
registerItem(registry, "lightning_crystal", new ItemCrystal());
registerItem(registry, "necromancy_crystal", new ItemCrystal());
registerItem(registry, "sorcery_crystal", new ItemCrystal());
registerItem(registry, "crystal_shard", new Item().setCreativeTab(WizardryTabs.WIZARDRY));
registerItem(registry, "grand_crystal", new Item().setCreativeTab(WizardryTabs.WIZARDRY));
@@ -59,7 +59,7 @@ public final class WizardryRecipes {
IForgeRegistry<IRecipe> registry = event.getRegistry();
FurnaceRecipes.instance().addSmeltingRecipeForBlock(WizardryBlocks.crystal_ore, new ItemStack(WizardryItems.crystal_magic), 0.5f);
FurnaceRecipes.instance().addSmeltingRecipeForBlock(WizardryBlocks.crystal_ore, new ItemStack(WizardryItems.magic_crystal), 0.5f);
// Mana flask recipes
@@ -256,8 +256,7 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
}
}
if((input.getItem() == WizardryItems.crystal_magic || input.getItem() == Item.getItemFromBlock(WizardryBlocks.crystal_block))
&& input.getMetadata() == 0){
if((input.getItem() == WizardryItems.magic_crystal || input.getItem() == Item.getItemFromBlock(WizardryBlocks.magic_crystal_block))){
if(Arrays.stream(receptacleElements).distinct().count() == 1 && receptacleElements[0] != null){ // All the same element
return new ItemStack(input.getItem(), input.getCount(), receptacleElements[0].ordinal());