made the nether altar work

This commit is contained in:
Ellpeck 2020-02-25 22:57:10 +01:00
parent 5be58608b6
commit b5777f715b
14 changed files with 107 additions and 44 deletions

View file

@ -173,7 +173,7 @@ public final class Helper {
}
}
}
return ActionResultType.FAIL;
return ActionResultType.CONSUME;
}
public static ICapabilityProvider makeRechargeProvider(ItemStack stack, boolean needsSelected) {

View file

@ -81,7 +81,7 @@ public final class NaturesAuraAPI {
* easily registered using {@link BasicAuraType#register()}.
*/
public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>();
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), DimensionType.OVERWORLD, 0xbef224, 0).register();
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), DimensionType.OVERWORLD, 0x89cc37, 0).register();
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), DimensionType.THE_NETHER, 0x871c0c, 0).register();
public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624, 0).register();
public static final BasicAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register();

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.api.recipes;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
@ -10,14 +11,16 @@ public class AltarRecipe {
public final ResourceLocation name;
public final Ingredient input;
public final ItemStack output;
public final IAuraType requiredType;
public final Ingredient catalyst;
public final int aura;
public final int time;
public AltarRecipe(ResourceLocation name, Ingredient input, ItemStack output, Ingredient catalyst, int aura, int time) {
public AltarRecipe(ResourceLocation name, Ingredient input, ItemStack output, IAuraType requiredType, Ingredient catalyst, int aura, int time) {
this.name = name;
this.input = input;
this.output = output;
this.requiredType = requiredType;
this.catalyst = catalyst;
this.aura = aura;
this.time = time;

View file

@ -42,6 +42,7 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
public BlockNatureAltar() {
super("nature_altar", TileEntityNatureAltar::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
this.setDefaultState(this.getDefaultState().with(NETHER, false));
}
@Override

View file

@ -30,7 +30,12 @@ import java.util.Random;
public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTileEntity {
private final BasicAuraContainer container = new BasicAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 500000);
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
@Override
public int getAuraColor() {
return IAuraType.forWorld(TileEntityNatureAltar.this.world).getColor();
}
};
private final ItemStack[] catalysts = new ItemStack[4];
public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) {
@Override
@ -54,12 +59,13 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
};
@OnlyIn(Dist.CLIENT)
public int bobTimer;
public boolean structureFine;
public StructureState structureState = StructureState.INVALID;
private AltarRecipe currentRecipe;
private int timer;
private int lastAura;
private boolean firstTick = true;
public TileEntityNatureAltar() {
super(ModTileEntities.NATURE_ALTAR);
@ -82,17 +88,19 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
}
if (!this.world.isRemote) {
if (this.world.getGameTime() % 40 == 0) {
boolean fine = Multiblocks.ALTAR.isComplete(this.world, this.pos);
if (fine != this.structureFine) {
this.structureFine = fine;
if (this.world.getGameTime() % 40 == 0 || this.firstTick) {
StructureState newState = this.getNewState();
if (newState != this.structureState) {
this.structureState = newState;
this.sendToClients();
}
this.firstTick = false;
}
if (this.structureFine) {
if (this.structureState != StructureState.INVALID) {
int space = this.container.storeAura(300, true);
if (space > 0 && this.container.isAcceptableType(IAuraType.forWorld(this.world))) {
IAuraType expectedType = this.structureState == StructureState.NETHER ? NaturesAuraAPI.TYPE_NETHER : NaturesAuraAPI.TYPE_OVERWORLD;
if (space > 0 && expectedType.isPresentInWorld(this.world)) {
int toStore = Math.min(IAuraChunk.getAuraInArea(this.world, this.pos, 20), space);
if (toStore > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos);
@ -107,7 +115,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
this.pos.getY() + rand.nextFloat() * 10F,
this.pos.getZ() + (float) rand.nextGaussian() * 10F,
this.pos.getX() + 0.5F, this.pos.getY() + 0.5F, this.pos.getZ() + 0.5F,
rand.nextFloat() * 0.1F + 0.1F, 0x89cc37, rand.nextFloat() * 1F + 1F
rand.nextFloat() * 0.1F + 0.1F, this.container.getAuraColor(), rand.nextFloat() * 1F + 1F
));
}
}
@ -122,7 +130,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
this.container.drainAura(stored, false);
if (this.world.getGameTime() % 4 == 0)
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ALTAR_CONVERSION));
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ALTAR_CONVERSION, this.container.getAuraColor()));
}
}
} else {
@ -140,7 +148,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
this.container.drainAura(req, false);
if (this.timer % 4 == 0)
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ALTAR_CONVERSION));
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ALTAR_CONVERSION, this.container.getAuraColor()));
this.timer++;
if (this.timer >= this.currentRecipe.time) {
@ -162,7 +170,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
this.sendToClients();
}
} else {
if (this.structureFine) {
if (this.structureState != StructureState.INVALID) {
if (rand.nextFloat() >= 0.7F) {
int fourths = this.container.getMaxAura() / 4;
if (this.container.getStoredAura() > 0) {
@ -195,7 +203,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
private AltarRecipe getRecipeForInput(ItemStack input) {
for (AltarRecipe recipe : NaturesAuraAPI.ALTAR_RECIPES.values()) {
if (recipe.input.test(input)) {
if (recipe.input.test(input) && (recipe.requiredType == null || recipe.requiredType.isPresentInWorld(this.world))) {
if (recipe.catalyst == Ingredient.EMPTY)
return recipe;
for (ItemStack stack : this.catalysts)
@ -206,12 +214,20 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
return null;
}
private StructureState getNewState() {
if (Multiblocks.ALTAR.isComplete(this.world, this.pos))
return StructureState.OVERWORLD;
if (Multiblocks.NETHER_ALTAR.isComplete(this.world, this.pos))
return StructureState.NETHER;
return StructureState.INVALID;
}
@Override
public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type);
if (type != SaveType.BLOCK) {
compound.put("items", this.items.serializeNBT());
compound.putBoolean("fine", this.structureFine);
compound.putString("state", this.structureState.name());
this.container.writeNBT(compound);
}
if (type == SaveType.TILE) {
@ -227,7 +243,8 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
super.readNBT(compound, type);
if (type != SaveType.BLOCK) {
this.items.deserializeNBT(compound.getCompound("items"));
this.structureFine = compound.getBoolean("fine");
if (compound.contains("state"))
this.structureState = StructureState.valueOf(compound.getString("state"));
this.container.readNBT(compound);
}
if (type == SaveType.TILE) {
@ -247,4 +264,10 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi
public IItemHandlerModifiable getItemHandler(Direction facing) {
return this.items;
}
public enum StructureState {
INVALID,
NETHER,
OVERWORLD
}
}

View file

@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableList;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.recipes.AltarRecipe;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import de.ellpeck.naturesaura.items.ItemAuraBottle;
import de.ellpeck.naturesaura.items.ModItems;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
@ -25,7 +27,7 @@ public class AltarCategory implements IRecipeCategory<AltarRecipe> {
private final ItemStack altar = new ItemStack(ModBlocks.NATURE_ALTAR);
public AltarCategory(IGuiHelper helper) {
this.background = helper.createDrawable(new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/jei/altar.png"), 0, 0, 78, 57);
this.background = helper.createDrawable(new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/jei/altar.png"), 0, 0, 103, 57);
}
@Override
@ -59,6 +61,8 @@ public class AltarCategory implements IRecipeCategory<AltarRecipe> {
builder.add(altarRecipe.input.getMatchingStacks());
if (altarRecipe.catalyst != Ingredient.EMPTY)
builder.add(altarRecipe.catalyst.getMatchingStacks());
if (altarRecipe.requiredType != null)
builder.add(ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), altarRecipe.requiredType));
iIngredients.setInputs(VanillaTypes.ITEM, builder.build());
iIngredients.setOutput(VanillaTypes.ITEM, altarRecipe.output);
}
@ -68,10 +72,13 @@ public class AltarCategory implements IRecipeCategory<AltarRecipe> {
IGuiItemStackGroup group = iRecipeLayout.getItemStacks();
group.init(0, true, 0, 18);
group.set(0, Arrays.asList(recipe.input.getMatchingStacks()));
group.init(1, false, 56, 18);
group.init(1, false, 80, 18);
group.set(1, recipe.output);
group.init(2, true, 26, 18);
group.set(2, recipe.catalyst == Ingredient.EMPTY ?
Collections.singletonList(this.altar) : Arrays.asList(recipe.catalyst.getMatchingStacks()));
group.init(3, true, 51, 18);
if (recipe.requiredType != null)
group.set(3, ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), recipe.requiredType));
}
}

View file

@ -2,6 +2,9 @@ package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.recipes.AltarRecipe;
import de.ellpeck.naturesaura.items.ItemAuraBottle;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariableProvider;
@ -30,6 +33,11 @@ public class ProcessorAltar implements IComponentProcessor {
return PatchouliAPI.instance.serializeIngredient(this.recipe.catalyst);
else
return null;
case "type":
if (this.recipe.requiredType != null)
return PatchouliAPI.instance.serializeItemStack(ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), this.recipe.requiredType));
else
return null;
case "name":
return this.recipe.output.getDisplayName().getFormattedText();
default:

View file

@ -120,13 +120,14 @@ public class PacketParticles {
}
}),
ALTAR_CONVERSION((message, world) -> {
int color = message.data[0];
for (int i = world.rand.nextInt(5) + 2; i >= 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + world.rand.nextFloat() * 0.5F,
message.posY + 0.9F + 0.25F * world.rand.nextFloat(),
message.posZ + 0.25F + world.rand.nextFloat() * 0.5F,
world.rand.nextGaussian() * 0.02F, world.rand.nextFloat() * 0.02F, world.rand.nextGaussian() * 0.02F,
0x00FF00, world.rand.nextFloat() * 1.5F + 0.75F, 20, 0F, false, true);
color, world.rand.nextFloat() * 1.5F + 0.75F, 20, 0F, false, true);
}
}),
POTION_GEN((message, world) -> {

View file

@ -157,29 +157,29 @@ public final class ModRecipes {
new AltarRecipe(res("infused_iron"),
ing(Items.IRON_INGOT), new ItemStack(ModItems.INFUSED_IRON),
Ingredient.EMPTY, 15000, 80).register();
NaturesAuraAPI.TYPE_OVERWORLD, Ingredient.EMPTY, 15000, 80).register();
new AltarRecipe(res("infused_iron_block"),
ing(Blocks.IRON_BLOCK), new ItemStack(ModBlocks.INFUSED_IRON_BLOCK),
Ingredient.EMPTY, 135000, 700).register();
NaturesAuraAPI.TYPE_OVERWORLD, Ingredient.EMPTY, 135000, 700).register();
new AltarRecipe(res("infused_stone"),
ing(Blocks.STONE), new ItemStack(ModBlocks.INFUSED_STONE),
Ingredient.EMPTY, 7500, 40).register();
NaturesAuraAPI.TYPE_OVERWORLD, Ingredient.EMPTY, 7500, 40).register();
Ingredient conversion = ing(ModBlocks.CONVERSION_CATALYST);
new AltarRecipe(res("breath"), nbtIng(ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), NaturesAuraAPI.TYPE_END)), new ItemStack(Items.DRAGON_BREATH), conversion, 20000, 80).register();
new AltarRecipe(res("leather"), ing(Items.ROTTEN_FLESH), new ItemStack(Items.LEATHER), conversion, 10000, 50).register();
new AltarRecipe(res("soul_sand"), ing(Blocks.SAND), new ItemStack(Blocks.SOUL_SAND), conversion, 5000, 100).register();
new AltarRecipe(res("nether_wart"), ing(Blocks.RED_MUSHROOM), new ItemStack(Items.NETHER_WART), conversion, 30000, 250).register();
new AltarRecipe(res("prismarine"), ing(Items.QUARTZ), new ItemStack(Items.PRISMARINE_SHARD), conversion, 55000, 200).register();
new AltarRecipe(res("water"), ing(Items.GLASS_BOTTLE), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER), conversion, 25000, 200).register();
new AltarRecipe(res("coal"), ing(Items.CHARCOAL), new ItemStack(Items.COAL), conversion, 30000, 250).register();
new AltarRecipe(res("breath"), nbtIng(ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), NaturesAuraAPI.TYPE_END)), new ItemStack(Items.DRAGON_BREATH), NaturesAuraAPI.TYPE_NETHER, conversion, 20000, 80).register();
new AltarRecipe(res("leather"), ing(Items.ROTTEN_FLESH), new ItemStack(Items.LEATHER), NaturesAuraAPI.TYPE_OVERWORLD, conversion, 10000, 50).register();
new AltarRecipe(res("soul_sand"), ing(Blocks.SAND), new ItemStack(Blocks.SOUL_SAND), NaturesAuraAPI.TYPE_NETHER, conversion, 5000, 100).register();
new AltarRecipe(res("nether_wart"), ing(Blocks.RED_MUSHROOM), new ItemStack(Items.NETHER_WART), NaturesAuraAPI.TYPE_NETHER, conversion, 30000, 250).register();
new AltarRecipe(res("prismarine"), ing(Items.QUARTZ), new ItemStack(Items.PRISMARINE_SHARD), NaturesAuraAPI.TYPE_NETHER, conversion, 55000, 200).register();
new AltarRecipe(res("water"), ing(Items.GLASS_BOTTLE), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER), NaturesAuraAPI.TYPE_OVERWORLD, conversion, 25000, 200).register();
new AltarRecipe(res("coal"), ing(Items.CHARCOAL), new ItemStack(Items.COAL), NaturesAuraAPI.TYPE_OVERWORLD, conversion, 30000, 250).register();
Ingredient crushing = ing(ModBlocks.CRUSHING_CATALYST);
new AltarRecipe(res("bone"), ing(Items.BONE), new ItemStack(Items.BONE_MEAL, 6), crushing, 3000, 40).register();
new AltarRecipe(res("sugar"), ing(Items.SUGAR_CANE), new ItemStack(Items.SUGAR, 3), crushing, 3000, 40).register();
new AltarRecipe(res("blaze"), ing(Items.BLAZE_ROD), new ItemStack(Items.BLAZE_POWDER, 4), crushing, 5000, 60).register();
new AltarRecipe(res("glowstone"), ing(Blocks.GLOWSTONE), new ItemStack(Items.GLOWSTONE_DUST, 4), crushing, 3000, 40).register();
new AltarRecipe(res("sand"), ing(Blocks.COBBLESTONE), new ItemStack(Blocks.SAND), crushing, 3000, 40).register();
new AltarRecipe(res("bone"), ing(Items.BONE), new ItemStack(Items.BONE_MEAL, 6), NaturesAuraAPI.TYPE_OVERWORLD, crushing, 3000, 40).register();
new AltarRecipe(res("sugar"), ing(Items.SUGAR_CANE), new ItemStack(Items.SUGAR, 3), NaturesAuraAPI.TYPE_OVERWORLD, crushing, 3000, 40).register();
new AltarRecipe(res("blaze"), ing(Items.BLAZE_ROD), new ItemStack(Items.BLAZE_POWDER, 4), NaturesAuraAPI.TYPE_NETHER, crushing, 5000, 60).register();
new AltarRecipe(res("glowstone"), ing(Blocks.GLOWSTONE), new ItemStack(Items.GLOWSTONE_DUST, 4), NaturesAuraAPI.TYPE_NETHER, crushing, 3000, 40).register();
new AltarRecipe(res("sand"), ing(Blocks.COBBLESTONE), new ItemStack(Blocks.SAND), NaturesAuraAPI.TYPE_OVERWORLD, crushing, 3000, 40).register();
new OfferingRecipe(res("sky_ingot"),
amountIng(new ItemStack(ModItems.INFUSED_IRON, 3)),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 743 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -4,13 +4,13 @@
{
"type": "item",
"item": "#input",
"x": 24,
"x": 14,
"y": 26
},
{
"type": "item",
"item": "#output",
"x": 76,
"x": 82,
"y": 26,
"link_recipe": true
},
@ -18,24 +18,30 @@
"group": "catalyst",
"type": "item",
"item": "#catalyst",
"x": 50,
"y": 28
"x": 36,
"y": 26
},
{
"type": "item",
"item": "#type",
"x": 58,
"y": 26
},
{
"group": "altar",
"type": "item",
"item": "naturesaura:nature_altar",
"x": 50,
"x": 36,
"y": 26
},
{
"type": "image",
"image": "naturesaura:textures/gui/patchouli/elements.png",
"x": 20,
"x": 10,
"y": 13,
"u": 0,
"v": 0,
"width": 75,
"width": 91,
"height": 44
},
{

View file

@ -6,7 +6,7 @@
"image": "naturesaura:textures/gui/patchouli/elements.png",
"x": 16,
"y": 13,
"u": 76,
"u": 92,
"v": 0,
"width": 84,
"height": 38

View file

@ -0,0 +1,14 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "minecraft:nether_bricks"
},
{
"item": "naturesaura:gold_fiber"
}
],
"result": {
"item": "naturesaura:gold_nether_brick"
}
}