mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-22 14:59:22 +01:00
added the rf converter
This commit is contained in:
parent
2e7405946a
commit
5954863a53
14 changed files with 271 additions and 10 deletions
|
@ -29,12 +29,17 @@ public final class ModConfig {
|
|||
|
||||
@Comment("The amount of blocks that can be between two Aura Field Creators for them to be connectable and work together")
|
||||
public int fieldCreatorRange = 10;
|
||||
|
||||
@Comment("The Aura to RF ratio used by the RF converter, read as aura*ratio = rf")
|
||||
public float auraToRFRatio = 5;
|
||||
}
|
||||
|
||||
public static class Features {
|
||||
|
||||
@Comment("If using Dragon's Breath in a Brewing Stand should not cause a glass bottle to appear")
|
||||
public boolean removeDragonBreathContainerItem = true;
|
||||
@Comment("If the RF converter block should be enabled")
|
||||
public boolean rfConverter = true;
|
||||
|
||||
@Comment("If the Aura Imbalance effect of grass and trees dying in the area if the Aura levels are too low should occur")
|
||||
public boolean grassDieEffect = true;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package de.ellpeck.naturesaura.blocks;
|
||||
|
||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
||||
public class BlockRFConverter extends BlockContainerImpl {
|
||||
|
||||
public BlockRFConverter() {
|
||||
super(Material.ROCK, "rf_converter", TileEntityRFConverter.class, "rf_converter");
|
||||
this.setSoundType(SoundType.STONE);
|
||||
this.setHardness(3F);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package de.ellpeck.naturesaura.blocks;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -43,4 +44,5 @@ public final class ModBlocks {
|
|||
public static final Block ANIMAL_SPAWNER = new BlockAnimalSpawner();
|
||||
public static final Block AUTO_CRAFTER = new BlockAutoCrafter();
|
||||
public static final Block GOLD_BRICK = new BlockImpl("gold_brick", Material.ROCK).setSoundType(SoundType.STONE).setHardness(2F);
|
||||
public static final Block RF_CONVERTER = ModConfig.enabledFeatures.rfConverter ? new BlockRFConverter() : null;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.function.BiFunction;
|
|||
public class Multiblock implements IMultiblock {
|
||||
|
||||
private final ResourceLocation name;
|
||||
private final Map<BlockPos, de.ellpeck.naturesaura.api.multiblock.Matcher> matchers = new HashMap<>();
|
||||
private final Map<BlockPos, Matcher> matchers = new HashMap<>();
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int depth;
|
||||
|
@ -129,9 +129,9 @@ public class Multiblock implements IMultiblock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean forEach(BlockPos center, char c, BiFunction<BlockPos, de.ellpeck.naturesaura.api.multiblock.Matcher, Boolean> function) {
|
||||
public boolean forEach(BlockPos center, char c, BiFunction<BlockPos, Matcher, Boolean> function) {
|
||||
BlockPos start = this.getStart(center);
|
||||
for (Map.Entry<BlockPos, de.ellpeck.naturesaura.api.multiblock.Matcher> entry : this.matchers.entrySet()) {
|
||||
for (Map.Entry<BlockPos, Matcher> entry : this.matchers.entrySet()) {
|
||||
BlockPos offset = entry.getKey();
|
||||
if (c == 0 || this.getChar(offset) == c)
|
||||
if (!function.apply(start.add(offset), entry.getValue()))
|
||||
|
@ -156,7 +156,7 @@ public class Multiblock implements IMultiblock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<BlockPos, de.ellpeck.naturesaura.api.multiblock.Matcher> getMatchers() {
|
||||
public Map<BlockPos, Matcher> getMatchers() {
|
||||
return this.matchers;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ellpeck.naturesaura.blocks.multi;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
|
||||
|
@ -81,4 +82,17 @@ public final class Multiblocks {
|
|||
'L', ModBlocks.ANCIENT_LOG,
|
||||
'0', ModBlocks.AUTO_CRAFTER,
|
||||
' ', Matcher.wildcard());
|
||||
public static final IMultiblock RF_CONVERTER = ModConfig.enabledFeatures.rfConverter ? NaturesAuraAPI.instance().createMultiblock(
|
||||
new ResourceLocation(NaturesAura.MOD_ID, "rf_converter"),
|
||||
new String[][]{
|
||||
{" ", " ", " ", " R ", " ", " ", " "},
|
||||
{" ", " R ", " ", " R R ", " ", " R ", " "},
|
||||
{" ", " ", " ", " ", " ", " ", " "},
|
||||
{" R ", " R R ", " ", "R 0 R", " ", " R R ", " R "},
|
||||
{" ", " ", " ", " ", " ", " ", " "},
|
||||
{" ", " R ", " ", " R R ", " ", " R ", " "},
|
||||
{" ", " ", " ", " R ", " ", " ", " "}},
|
||||
'R', Blocks.REDSTONE_BLOCK,
|
||||
'0', ModBlocks.RF_CONVERTER,
|
||||
' ', Matcher.wildcard()) : null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.EnergyStorage;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class TileEntityRFConverter extends TileEntityImpl implements ITickable {
|
||||
|
||||
public final RFStorage storage = new RFStorage();
|
||||
private int lastEnergy;
|
||||
|
||||
@Override
|
||||
public void writeNBT(NBTTagCompound compound, SaveType type) {
|
||||
super.writeNBT(compound, type);
|
||||
compound.setInteger("energy", this.storage.getEnergyStored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(NBTTagCompound compound, SaveType type) {
|
||||
super.readNBT(compound, type);
|
||||
this.storage.setEnergy(compound.getInteger("energy"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (!this.world.isRemote) {
|
||||
if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getTotalWorldTime() % 10 == 0) {
|
||||
this.sendToClients();
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
}
|
||||
|
||||
for (EnumFacing facing : EnumFacing.VALUES) {
|
||||
TileEntity tile = this.world.getTileEntity(this.pos.offset(facing));
|
||||
if (tile == null || !tile.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite()))
|
||||
continue;
|
||||
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite());
|
||||
if (storage == null)
|
||||
continue;
|
||||
int canStore = storage.receiveEnergy(Integer.MAX_VALUE, true);
|
||||
if (canStore <= 0)
|
||||
continue;
|
||||
int extracted = this.storage.extractEnergy(canStore, false);
|
||||
if (extracted <= 0)
|
||||
continue;
|
||||
storage.receiveEnergy(extracted, false);
|
||||
break;
|
||||
}
|
||||
|
||||
int emptyPart = this.storage.getMaxEnergyStored() - this.storage.getEnergyStored();
|
||||
if (emptyPart <= 0)
|
||||
return;
|
||||
if (this.world.getTotalWorldTime() % 20 != 0)
|
||||
return;
|
||||
if (!Multiblocks.RF_CONVERTER.isComplete(this.world, this.pos))
|
||||
return;
|
||||
|
||||
int aura = IAuraChunk.getAuraInArea(this.world, this.pos, 45);
|
||||
if (aura <= IAuraChunk.DEFAULT_AURA)
|
||||
return;
|
||||
int amountToGen = Math.min(Math.min(10000, aura / 10), emptyPart);
|
||||
int amountToUse = MathHelper.ceil(amountToGen / ModConfig.general.auraToRFRatio);
|
||||
|
||||
this.storage.setEnergy(this.storage.getEnergyStored() + amountToGen);
|
||||
BlockPos pos = IAuraChunk.getHighestSpot(this.world, this.pos, 45, this.pos);
|
||||
IAuraChunk.getAuraChunk(this.world, pos).drainAura(pos, amountToUse);
|
||||
|
||||
PacketHandler.sendToAllAround(this.world, this.pos, 32,
|
||||
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), 20));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityEnergy.ENERGY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityEnergy.ENERGY)
|
||||
return (T) this.storage;
|
||||
else
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
public static class RFStorage extends EnergyStorage {
|
||||
|
||||
public RFStorage() {
|
||||
super(50000, 0, 2000);
|
||||
}
|
||||
|
||||
public void setEnergy(int energy) {
|
||||
this.energy = energy;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
package de.ellpeck.naturesaura.compat;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import vazkii.patchouli.api.PatchouliAPI;
|
||||
|
||||
public final class Compat {
|
||||
|
||||
|
@ -17,6 +20,8 @@ public final class Compat {
|
|||
|
||||
if (baubles)
|
||||
MinecraftForge.EVENT_BUS.register(new BaublesCompat());
|
||||
|
||||
PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.enabledFeatures.rfConverter);
|
||||
}
|
||||
|
||||
public static void postInit() {
|
||||
|
|
|
@ -8,6 +8,7 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|||
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
|
||||
import de.ellpeck.naturesaura.compat.Compat;
|
||||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import de.ellpeck.naturesaura.particles.ParticleHandler;
|
||||
|
@ -28,6 +29,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
|||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.energy.EnergyStorage;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
|
@ -291,15 +293,22 @@ public class ClientEvents {
|
|||
|
||||
IBlockState state = mc.world.getBlockState(pos);
|
||||
ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player);
|
||||
this.drawContainerInfo(container, mc, res, 35, blockStack.getDisplayName());
|
||||
this.drawContainerInfo(container.getStoredAura(), container.getMaxAura(), container.getAuraColor(),
|
||||
mc, res, 35, blockStack.getDisplayName(), null);
|
||||
|
||||
if (tile instanceof TileEntityNatureAltar) {
|
||||
ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler(null).getStackInSlot(0);
|
||||
if (!tileStack.isEmpty() && tileStack.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
|
||||
IAuraContainer stackContainer = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null);
|
||||
this.drawContainerInfo(stackContainer, mc, res, 55, tileStack.getDisplayName());
|
||||
IAuraContainer stackCont = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null);
|
||||
this.drawContainerInfo(stackCont.getStoredAura(), stackCont.getMaxAura(), stackCont.getAuraColor(),
|
||||
mc, res, 55, tileStack.getDisplayName(), null);
|
||||
}
|
||||
}
|
||||
} else if (tile instanceof TileEntityRFConverter) {
|
||||
EnergyStorage storage = ((TileEntityRFConverter) tile).storage;
|
||||
this.drawContainerInfo(storage.getEnergyStored(), storage.getMaxEnergyStored(), 0xcc4916,
|
||||
mc, res, 35, I18n.format("tile.naturesaura.rf_converter.name"),
|
||||
storage.getEnergyStored() + " / " + storage.getMaxEnergyStored() + " RF");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,13 +321,12 @@ public class ClientEvents {
|
|||
mc.profiler.endSection();
|
||||
}
|
||||
|
||||
private void drawContainerInfo(IAuraContainer container, Minecraft mc, ScaledResolution res, int yOffset, String name) {
|
||||
int color = container.getAuraColor();
|
||||
private void drawContainerInfo(int stored, int max, int color, Minecraft mc, ScaledResolution res, int yOffset, String name, String textBelow) {
|
||||
GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
|
||||
|
||||
int x = res.getScaledWidth() / 2 - 40;
|
||||
int y = res.getScaledHeight() / 2 + yOffset;
|
||||
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
|
||||
int width = MathHelper.ceil(stored / (float) max * 80);
|
||||
|
||||
mc.getTextureManager().bindTexture(OVERLAYS);
|
||||
if (width < 80)
|
||||
|
@ -327,5 +335,8 @@ public class ClientEvents {
|
|||
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256);
|
||||
|
||||
mc.fontRenderer.drawString(name, x + 40 - mc.fontRenderer.getStringWidth(name) / 2F, y - 9, color, true);
|
||||
|
||||
if (textBelow != null)
|
||||
mc.fontRenderer.drawString(textBelow, x + 40 - mc.fontRenderer.getStringWidth(textBelow) / 2F, y + 7, color, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -321,6 +321,22 @@ public class PacketParticles implements IMessage {
|
|||
world.rand.nextGaussian() * 0.02F,
|
||||
0x16b7b2, 1.5F, 40, 0F, false, true);
|
||||
break;
|
||||
case 20: // RF converter
|
||||
for (int i = world.rand.nextInt(5) + 2; i >= 0; i--)
|
||||
Multiblocks.RF_CONVERTER.forEach(new BlockPos(message.posX, message.posY, message.posZ), 'R', (blockPos, matcher) -> {
|
||||
if (world.rand.nextFloat() < 0.35F) {
|
||||
NaturesAuraAPI.instance().spawnParticleStream(
|
||||
blockPos.getX() + world.rand.nextFloat(),
|
||||
blockPos.getY() + world.rand.nextFloat(),
|
||||
blockPos.getZ() + world.rand.nextFloat(),
|
||||
message.posX + world.rand.nextFloat(),
|
||||
message.posY + world.rand.nextFloat(),
|
||||
message.posZ + world.rand.nextFloat(),
|
||||
0.05F, 0xff1a05, 1.5F);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"forge_marker": 1,
|
||||
"defaults": {
|
||||
"model": "minecraft:cube_all",
|
||||
"textures": {
|
||||
"all": "naturesaura:blocks/rf_converter"
|
||||
},
|
||||
"transform": "forge:default-block"
|
||||
},
|
||||
"variants": {
|
||||
"normal": [{}],
|
||||
"inventory": [{}]
|
||||
}
|
||||
}
|
|
@ -40,6 +40,7 @@ tile.naturesaura.grated_chute.name=Adept Hopper
|
|||
tile.naturesaura.animal_spawner.name=Altar of Birthing
|
||||
tile.naturesaura.auto_crafter.name=Automatic Constructor
|
||||
tile.naturesaura.gold_brick.name=Golden Stone Bricks
|
||||
tile.naturesaura.rf_converter.name=Energetic Aura Forge
|
||||
|
||||
item.naturesaura.eye.name=Environmental Eye
|
||||
item.naturesaura.eye_improved.name=Environmental Ocular
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "Energetic Aura Forge",
|
||||
"icon": "naturesaura:rf_converter",
|
||||
"category": "using",
|
||||
"advancement": "naturesaura:sky_ingot",
|
||||
"flag": "naturesaura:rf_converter",
|
||||
"pages": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "While $(aura) is quite versatile and useful, it's most definitely not the only $(thing)energy source$() around. In recent history, new sources of energy that aren't considered natural have been $(italic)forged$() by the people. Sometimes, it might prove useful to have such a power source at one's disposal instead. The $(item)Energetic Aura Forge$() directly converts $(aura) into what is known to most people as $(thing)Redstone Flux$(),"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": "to some as $(thing)Forge Energy$() and to even others as $(thing)Crystal Flux$().$(br)To achieve this, simply place the $(item)Energetic Aura Forge$() with the accompanied structure as shown on the next page. Then, any excess amount of $(aura) in the area will automatically be turned into electrical energy. The more $(aura) there is present, the faster the conversion process will go.$(br)Additionally, having the $(l:items/eye)Environmental Eye$() equipped will display the amount of energy in the device."
|
||||
},
|
||||
{
|
||||
"type": "multiblock",
|
||||
"multiblock_id": "naturesaura:rf_converter",
|
||||
"text": "Creating the structure around the $(item)Energetic Aura Forge$()"
|
||||
},
|
||||
{
|
||||
"type": "crafting",
|
||||
"text": "Creating the $(item)Energetic Aura Forge$()",
|
||||
"recipe": "naturesaura:rf_converter"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"type": "forge:ore_shaped",
|
||||
"pattern": [
|
||||
"RWR",
|
||||
"ITI",
|
||||
"ROR"
|
||||
],
|
||||
"key": {
|
||||
"T": {
|
||||
"item": "naturesaura:conversion_catalyst"
|
||||
},
|
||||
"R": {
|
||||
"item": "minecraft:redstone_block"
|
||||
},
|
||||
"I": {
|
||||
"item": "naturesaura:sky_ingot"
|
||||
},
|
||||
"W": {
|
||||
"type": "minecraft:item_nbt",
|
||||
"item": "naturesaura:aura_bottle",
|
||||
"nbt": {
|
||||
"stored_type": "naturesaura:nether"
|
||||
}
|
||||
},
|
||||
"O": {
|
||||
"type": "minecraft:item_nbt",
|
||||
"item": "naturesaura:aura_bottle",
|
||||
"nbt": {
|
||||
"stored_type": "naturesaura:overworld"
|
||||
}
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "naturesaura:rf_converter"
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"type": "minecraft:item_exists",
|
||||
"item": "naturesaura:rf_converter"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 703 B |
Loading…
Reference in a new issue