Tile -> BlockEntity + some more refactors
This commit is contained in:
parent
7f8674f1ca
commit
dbc89adaf7
193 changed files with 3194 additions and 3214 deletions
115
src/main/java/techreborn/blockentity/AlarmBlockEntity.java
Normal file
115
src/main/java/techreborn/blockentity/AlarmBlockEntity.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.Tickable;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.util.ChatUtils;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.blocks.BlockAlarm;
|
||||
import techreborn.init.ModSounds;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.utils.MessageIDs;
|
||||
|
||||
public class AlarmBlockEntity extends BlockEntity
|
||||
implements Tickable, IToolDrop {
|
||||
private int selectedSound = 1;
|
||||
|
||||
public AlarmBlockEntity() {
|
||||
super(TRBlockEntities.ALARM);
|
||||
}
|
||||
|
||||
public void rightClick() {
|
||||
if (!world.isClient) {
|
||||
if (selectedSound < 3) {
|
||||
selectedSound++;
|
||||
} else {
|
||||
selectedSound = 1;
|
||||
}
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.alarmID, new LiteralText(
|
||||
Formatting.GRAY + StringUtils.t("techreborn.message.alarm") + " " + "Alarm " + selectedSound));
|
||||
}
|
||||
}
|
||||
|
||||
// BlockEntity
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag compound) {
|
||||
if (compound == null) {
|
||||
compound = new CompoundTag();
|
||||
}
|
||||
compound.putInt("selectedSound", this.selectedSound);
|
||||
return super.toTag(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag compound) {
|
||||
if (compound != null && compound.containsKey("selectedSound")) {
|
||||
selectedSound = compound.getInt("selectedSound");
|
||||
}
|
||||
super.fromTag(compound);
|
||||
}
|
||||
|
||||
//TODO 1.13 seems to be gone?
|
||||
// @Override
|
||||
// public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// ITickable
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!world.isClient && world.getTime() % 25 == 0 && world.isReceivingRedstonePower(getPos())) {
|
||||
BlockAlarm.setActive(true, world, pos);
|
||||
switch (selectedSound) {
|
||||
case 1:
|
||||
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F);
|
||||
break;
|
||||
case 2:
|
||||
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_2, SoundCategory.BLOCKS, 4F, 1F);
|
||||
break;
|
||||
case 3:
|
||||
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_3, SoundCategory.BLOCKS, 4F, 1F);
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (!world.isClient && world.getTime() % 25 == 0) {
|
||||
BlockAlarm.setActive(false, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.ALARM.getStack();
|
||||
}
|
||||
}
|
128
src/main/java/techreborn/blockentity/ChargeOMatBlockEntity.java
Normal file
128
src/main/java/techreborn/blockentity/ChargeOMatBlockEntity.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.powerSystem.ExternalPowerSystems;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxOutput", comment = "Charge Bench Max Output (Value in EU)")
|
||||
public static int maxOutput = 512;
|
||||
@ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxInput", comment = "Charge Bench Max Input (Value in EU)")
|
||||
public static int maxInput = 512;
|
||||
@ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxEnergy", comment = "Charge Bench Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 100_000_000;
|
||||
|
||||
public RebornInventory<ChargeOMatBlockEntity> inventory = new RebornInventory<>(6, "ChargeOMatBlockEntity", 64, this).withConfiguredAccess();
|
||||
|
||||
public ChargeOMatBlockEntity() {
|
||||
super(TRBlockEntities.CHARGE_O_MAT);
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 6; i++) {
|
||||
ItemStack stack = inventory.getInvStack(i);
|
||||
|
||||
if (!stack.isEmpty()) {
|
||||
ExternalPowerSystems.chargeItem(this, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.CHARGE_O_MAT.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<ChargeOMatBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("chargebench").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).energySlot(0, 62, 25).energySlot(1, 98, 25).energySlot(2, 62, 45).energySlot(3, 98, 45)
|
||||
.energySlot(4, 62, 65).energySlot(5, 98, 65).syncEnergyValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class DigitalChestBlockEntity extends TechStorageBaseBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "digital_chest", key = "DigitalChestMaxStorage", comment = "Maximum amount of items a Digital Chest can store")
|
||||
public static int maxStorage = 32768;
|
||||
|
||||
public DigitalChestBlockEntity() {
|
||||
super(TRBlockEntities.DIGITAL_CHEST, "DigitalChestBlockEntity", maxStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("digitalchest").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.recipe.IRecipeCrafterProvider;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
||||
/**
|
||||
* @author drcrazy
|
||||
*
|
||||
*/
|
||||
public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IRecipeCrafterProvider{
|
||||
|
||||
public String name;
|
||||
public int maxInput;
|
||||
public int maxEnergy;
|
||||
public Block toolDrop;
|
||||
public int energySlot;
|
||||
public RebornInventory<?> inventory;
|
||||
public RecipeCrafter crafter;
|
||||
|
||||
/**
|
||||
* @param name String Name for a blockEntity. Do we need it at all?
|
||||
* @param maxInput int Maximum energy input, value in EU
|
||||
* @param maxEnergy int Maximum energy buffer, value in EU
|
||||
* @param toolDrop Block Block to drop with wrench
|
||||
* @param energySlot int Energy slot to use to charge machine from battery
|
||||
*/
|
||||
public GenericMachineBlockEntity(BlockEntityType<?> blockEntityType, String name, int maxInput, int maxEnergy, Block toolDrop, int energySlot) {
|
||||
super(blockEntityType);
|
||||
this.name = "BlockEntity" + name;
|
||||
this.maxInput = maxInput;
|
||||
this.maxEnergy = maxEnergy;
|
||||
this.toolDrop = toolDrop;
|
||||
this.energySlot = energySlot;
|
||||
checkTier();
|
||||
}
|
||||
|
||||
public int getProgressScaled(final int scale) {
|
||||
if (crafter != null && crafter.currentTickTime != 0) {
|
||||
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient) {
|
||||
charge(energySlot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity p0) {
|
||||
return new ItemStack(toolDrop, 1);
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<?> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IRecipeCrafterProvider
|
||||
@Override
|
||||
public RecipeCrafter getRecipeCrafter() {
|
||||
return crafter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.items.DynamicCell;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class IndustrialCentrifugeBlockEntity extends GenericMachineBlockEntity implements IContainerProvider, IListInfoProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "centrifuge", key = "CentrifugeMaxInput", comment = "Centrifuge Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "centrifuge", key = "CentrifugeMaxEnergy", comment = "Centrifuge Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public IndustrialCentrifugeBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_CENTRIFUGE, "IndustrialCentrifuge", maxInput, maxEnergy, TRContent.Machine.INDUSTRIAL_CENTRIFUGE.block, 6);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3, 4, 5 };
|
||||
this.inventory = new RebornInventory<>(7, "IndustrialCentrifugeBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.CENTRIFUGE, this, 2, 4, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("centrifuge").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this)
|
||||
.filterSlot(1, 40, 54, stack -> ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true))
|
||||
.filterSlot(0, 40, 34, stack -> !ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true))
|
||||
.outputSlot(2, 82, 44).outputSlot(3, 101, 25)
|
||||
.outputSlot(4, 120, 44).outputSlot(5, 101, 63).energySlot(6, 8, 72).syncEnergyValue()
|
||||
.syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
||||
super.addInfo(info, isReal, hasData);
|
||||
info.add(new LiteralText("Round and round it goes"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import reborncore.common.multiblock.MultiblockControllerBase;
|
||||
import reborncore.common.multiblock.rectangular.RectangularMultiblockBlockEntityBase;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.multiblocks.MultiBlockCasing;
|
||||
|
||||
public class MachineCasingBlockEntity extends RectangularMultiblockBlockEntityBase {
|
||||
|
||||
public MachineCasingBlockEntity() {
|
||||
super(TRBlockEntities.MACHINE_CASINGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineActivated() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineDeactivated() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiblockControllerBase createNewMultiblock() {
|
||||
return new MultiBlockCasing(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends MultiblockControllerBase> getMultiblockControllerType() {
|
||||
return MultiBlockCasing.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForFrame() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForSides() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForTop() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForBottom() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForInterior() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiBlockCasing getMultiblockController() {
|
||||
return (MultiBlockCasing) super.getMultiblockController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TechStorageBaseBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IToolDrop, IListInfoProvider {
|
||||
|
||||
public final int maxCapacity;
|
||||
public final RebornInventory<TechStorageBaseBlockEntity> inventory;
|
||||
public ItemStack storedItem;
|
||||
|
||||
public TechStorageBaseBlockEntity(BlockEntityType<?> blockEntityTypeIn, String name, int maxCapacity) {
|
||||
super(blockEntityTypeIn);
|
||||
this.maxCapacity = maxCapacity;
|
||||
storedItem = ItemStack.EMPTY;
|
||||
inventory = new RebornInventory<>(3, name, maxCapacity, this).withConfiguredAccess();
|
||||
}
|
||||
|
||||
public void readWithoutCoords(CompoundTag tagCompound) {
|
||||
|
||||
storedItem = ItemStack.EMPTY;
|
||||
|
||||
if (tagCompound.containsKey("storedStack")) {
|
||||
storedItem = ItemStack.fromTag(tagCompound.getCompound("storedStack"));
|
||||
}
|
||||
|
||||
if (!storedItem.isEmpty()) {
|
||||
storedItem.setCount(Math.min(tagCompound.getInt("storedQuantity"), this.maxCapacity));
|
||||
}
|
||||
|
||||
inventory.read(tagCompound);
|
||||
}
|
||||
|
||||
public CompoundTag writeWithoutCoords(CompoundTag tagCompound) {
|
||||
if (!storedItem.isEmpty()) {
|
||||
ItemStack temp = storedItem.copy();
|
||||
if (storedItem.getCount() > storedItem.getMaxCount()) {
|
||||
temp.setCount(storedItem.getMaxCount());
|
||||
}
|
||||
tagCompound.put("storedStack", temp.toTag(new CompoundTag()));
|
||||
tagCompound.putInt("storedQuantity", Math.min(storedItem.getCount(), maxCapacity));
|
||||
} else {
|
||||
tagCompound.putInt("storedQuantity", 0);
|
||||
}
|
||||
inventory.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT() {
|
||||
CompoundTag blockEntity = new CompoundTag();
|
||||
ItemStack dropStack = new ItemStack(getBlockType(), 1);
|
||||
writeWithoutCoords(blockEntity);
|
||||
dropStack.setTag(new CompoundTag());
|
||||
dropStack.getTag().put("blockEntity", blockEntity);
|
||||
storedItem.setCount(0);
|
||||
inventory.setInvStack(1, ItemStack.EMPTY);
|
||||
syncWithAll();
|
||||
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
public int getStoredCount() {
|
||||
return storedItem.getCount();
|
||||
}
|
||||
|
||||
public List<ItemStack> getContentDrops() {
|
||||
ArrayList<ItemStack> stacks = new ArrayList<>();
|
||||
|
||||
if (!getStoredItemType().isEmpty()) {
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
stacks.add(inventory.getInvStack(1));
|
||||
}
|
||||
int size = storedItem.getMaxCount();
|
||||
for (int i = 0; i < getStoredCount() / size; i++) {
|
||||
ItemStack droped = storedItem.copy();
|
||||
droped.setCount(size);
|
||||
stacks.add(droped);
|
||||
}
|
||||
if (getStoredCount() % size != 0) {
|
||||
ItemStack droped = storedItem.copy();
|
||||
droped.setCount(getStoredCount() % size);
|
||||
stacks.add(droped);
|
||||
}
|
||||
}
|
||||
|
||||
return stacks;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient) {
|
||||
ItemStack outputStack = ItemStack.EMPTY;
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
outputStack = inventory.getInvStack(1);
|
||||
}
|
||||
if (!inventory.getInvStack(0).isEmpty()
|
||||
&& (storedItem.getCount() + outputStack.getCount()) < maxCapacity) {
|
||||
ItemStack inputStack = inventory.getInvStack(0);
|
||||
if (getStoredItemType().isEmpty()
|
||||
|| (storedItem.isEmpty() && ItemUtils.isItemEqual(inputStack, outputStack, true, true))) {
|
||||
|
||||
storedItem = inputStack;
|
||||
inventory.setInvStack(0, ItemStack.EMPTY);
|
||||
} else if (ItemUtils.isItemEqual(getStoredItemType(), inputStack, true, true)) {
|
||||
int reminder = maxCapacity - storedItem.getCount() - outputStack.getCount();
|
||||
if (inputStack.getCount() <= reminder) {
|
||||
setStoredItemCount(inputStack.getCount());
|
||||
inventory.setInvStack(0, ItemStack.EMPTY);
|
||||
} else {
|
||||
setStoredItemCount(maxCapacity - outputStack.getCount());
|
||||
inventory.getInvStack(0).decrement(reminder);
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
}
|
||||
|
||||
if (!storedItem.isEmpty()) {
|
||||
if (outputStack.isEmpty()) {
|
||||
|
||||
ItemStack delivered = storedItem.copy();
|
||||
delivered.setCount(Math.min(storedItem.getCount(), delivered.getMaxCount()));
|
||||
storedItem.decrement(delivered.getCount());
|
||||
|
||||
if (storedItem.isEmpty()) {
|
||||
storedItem = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
inventory.setInvStack(1, delivered);
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
} else if (ItemUtils.isItemEqual(storedItem, outputStack, true, true)
|
||||
&& outputStack.getCount() < outputStack.getMaxCount()) {
|
||||
|
||||
int wanted = Math.min(storedItem.getCount(),
|
||||
outputStack.getMaxCount() - outputStack.getCount());
|
||||
outputStack.setCount(outputStack.getCount() + wanted);
|
||||
storedItem.decrement(wanted);
|
||||
|
||||
if (storedItem.isEmpty()) {
|
||||
storedItem = ItemStack.EMPTY;
|
||||
}
|
||||
markDirty();
|
||||
syncWithAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
readWithoutCoords(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
writeWithoutCoords(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<TechStorageBaseBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return getDropWithNBT();
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
if (isReal || hasData) {
|
||||
int size = 0;
|
||||
String name = "of nothing";
|
||||
if (!storedItem.isEmpty()) {
|
||||
name = storedItem.getName().getString();
|
||||
size += storedItem.getCount();
|
||||
}
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
name = inventory.getInvStack(1).getName().getString();
|
||||
size += inventory.getInvStack(1).getCount();
|
||||
}
|
||||
info.add(new LiteralText(size + " " + name));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getStoredItemType() {
|
||||
return storedItem.isEmpty() ? inventory.getInvStack(1) : storedItem;
|
||||
}
|
||||
|
||||
|
||||
public void setStoredItemCount(int amount) {
|
||||
storedItem.increment(amount);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void setStoredItemType(ItemStack type, int amount) {
|
||||
storedItem = type;
|
||||
storedItem.setCount(amount);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public int getMaxStoredCount() {
|
||||
return maxCapacity;
|
||||
}
|
||||
}
|
177
src/main/java/techreborn/blockentity/cable/CableBlockEntity.java
Normal file
177
src/main/java/techreborn/blockentity/cable/CableBlockEntity.java
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.cable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.blocks.cable.BlockCable;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 19/05/2017.
|
||||
*/
|
||||
|
||||
public class CableBlockEntity extends BlockEntity
|
||||
implements Tickable, IListInfoProvider, IToolDrop {
|
||||
|
||||
public int power = 0;
|
||||
private int transferRate = 0;
|
||||
private TRContent.Cables cableType = null;
|
||||
private ArrayList<Direction> sendingFace = new ArrayList<Direction>();
|
||||
int ticksSinceLastChange = 0;
|
||||
|
||||
public CableBlockEntity() {
|
||||
super(TRBlockEntities.CABLE);
|
||||
}
|
||||
|
||||
private TRContent.Cables getCableType() {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if(block instanceof BlockCable){
|
||||
return ((BlockCable) block).type;
|
||||
}
|
||||
//Something has gone wrong if this happens
|
||||
return TRContent.Cables.COPPER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toInitialChunkDataTag() {
|
||||
return toTag(new CompoundTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityUpdateS2CPacket toUpdatePacket() {
|
||||
CompoundTag nbtTag = new CompoundTag();
|
||||
toTag(nbtTag);
|
||||
return new BlockEntityUpdateS2CPacket(getPos(), 1, nbtTag);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag compound) {
|
||||
super.fromTag(compound);
|
||||
if (compound.containsKey("CableBlockEntity")) {
|
||||
power = compound.getCompound("CableBlockEntity").getInt("power");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag compound) {
|
||||
super.toTag(compound);
|
||||
if (power > 0) {
|
||||
CompoundTag data = new CompoundTag();
|
||||
compound.put("CableBlockEntity", data);
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ITickable
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cableType == null ){
|
||||
cableType = getCableType();
|
||||
transferRate = cableType.transferRate * RebornCoreConfig.euPerFU;
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
if (ticksSinceLastChange >= 10) {
|
||||
sendingFace.clear();
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
//TODO needs a full recode to not use a specific power net
|
||||
|
||||
// ArrayList<IEnergyStorage> acceptors = new ArrayList<IEnergyStorage>();
|
||||
// for (Direction face : Direction.values()) {
|
||||
// BlockEntity blockEntity = world.getBlockEntity(pos.offset(face));
|
||||
//
|
||||
// if (blockEntity == null) {
|
||||
// continue;
|
||||
// } else if (blockEntity instanceof TileCable) {
|
||||
// TileCable cable = (TileCable) blockEntity;
|
||||
// if (power > cable.power && cable.canReceiveFromFace(face.getOpposite())) {
|
||||
// acceptors.add((IEnergyStorage) blockEntity);
|
||||
// if (!sendingFace.contains(face)) {
|
||||
// sendingFace.add(face);
|
||||
// }
|
||||
// }
|
||||
// } else if (blockEntity.getCapability(CapabilityEnergy.ENERGY, face.getOpposite()).isPresent()) {
|
||||
// IEnergyStorage energyTile = blockEntity.getCapability(CapabilityEnergy.ENERGY, face.getOpposite()).orElse(null);
|
||||
// if (energyTile != null && energyTile.canReceive()) {
|
||||
// acceptors.add(energyTile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (acceptors.size() > 0 ) {
|
||||
// for (IEnergyStorage blockEntity : acceptors) {
|
||||
// int drain = Math.min(power, transferRate);
|
||||
// if (drain > 0 && blockEntity.receiveEnergy(drain, true) > 0) {
|
||||
// int move = blockEntity.receiveEnergy(drain, false);
|
||||
// extractEnergy(move, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
if (isReal) {
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.transferRate") + ": "
|
||||
+ Formatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(transferRate / RebornCoreConfig.euPerFU) + "/t"));
|
||||
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.tier") + ": "
|
||||
+ Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(cableType.tier.toString())));
|
||||
}
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return new ItemStack(getCableType().block);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,467 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.fusionReactor;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import reborncore.common.util.Torus;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.reactor.FusionReactorRecipe;
|
||||
import techreborn.api.reactor.FusionReactorRecipeHelper;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class FusionControlComputerBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxInput", comment = "Fusion Reactor Max Input (Value in EU)")
|
||||
public static int maxInput = 8192;
|
||||
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxOutput", comment = "Fusion Reactor Max Output (Value in EU)")
|
||||
public static int maxOutput = 1_000_000;
|
||||
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxEnergy", comment = "Fusion Reactor Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 100_000_000;
|
||||
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxCoilSize", comment = "Fusion Reactor Max Coil size (Radius)")
|
||||
public static int maxCoilSize = 50;
|
||||
|
||||
public RebornInventory<FusionControlComputerBlockEntity> inventory;
|
||||
|
||||
public int coilCount = 0;
|
||||
public int crafingTickTime = 0;
|
||||
public int finalTickTime = 0;
|
||||
public int neededPower = 0;
|
||||
public int size = 6;
|
||||
public int state = -1;
|
||||
int topStackSlot = 0;
|
||||
int bottomStackSlot = 1;
|
||||
int outputStackSlot = 2;
|
||||
FusionReactorRecipe currentRecipe = null;
|
||||
boolean hasStartedCrafting = false;
|
||||
long lastTick = -1;
|
||||
|
||||
public FusionControlComputerBlockEntity() {
|
||||
super(TRBlockEntities.FUSION_CONTROL_COMPUTER);
|
||||
checkOverfill = false;
|
||||
this.inventory = new RebornInventory<>(3, "FusionControlComputerBlockEntity", 64, this).withConfiguredAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that reactor has all necessary coils in place
|
||||
*
|
||||
* @return boolean Return true if coils are present
|
||||
*/
|
||||
public boolean checkCoils() {
|
||||
List<BlockPos> coils = Torus.generate(pos, size);
|
||||
for(BlockPos coilPos : coils){
|
||||
if (!isCoil(coilPos)) {
|
||||
coilCount = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
coilCount = coils.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if block is fusion coil
|
||||
*
|
||||
* @param pos coordinate for block
|
||||
* @return boolean Returns true if block is fusion coil
|
||||
*/
|
||||
public boolean isCoil(BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == TRContent.Machine.FUSION_COIL.block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets crafter progress and recipe
|
||||
*/
|
||||
private void resetCrafter() {
|
||||
currentRecipe = null;
|
||||
crafingTickTime = 0;
|
||||
finalTickTime = 0;
|
||||
neededPower = 0;
|
||||
hasStartedCrafting = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that ItemStack could be inserted into slot provided, including check
|
||||
* for existing item in slot and maximum stack size
|
||||
*
|
||||
* @param stack ItemStack ItemStack to insert
|
||||
* @param slot int Slot ID to check
|
||||
* @param tags boolean Should we use tags
|
||||
* @return boolean Returns true if ItemStack will fit into slot
|
||||
*/
|
||||
public boolean canFitStack(ItemStack stack, int slot, boolean tags) {// Checks to see if it can
|
||||
// fit the stack
|
||||
if (stack.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (inventory.getInvStack(slot).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(inventory.getInvStack(slot), stack, true, tags)) {
|
||||
if (stack.getCount() + inventory.getInvStack(slot).getCount() <= stack.getMaxCount()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns progress scaled to input value
|
||||
*
|
||||
* @param scale int Maximum value for progress
|
||||
* @return int Scale of progress
|
||||
*/
|
||||
public int getProgressScaled(int scale) {
|
||||
if (crafingTickTime != 0 && finalTickTime != 0) {
|
||||
return crafingTickTime * scale / finalTickTime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to set current recipe based in inputs in reactor
|
||||
*/
|
||||
private void updateCurrentRecipe() {
|
||||
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
|
||||
if (validateReactorRecipe(reactorRecipe)) {
|
||||
currentRecipe = reactorRecipe;
|
||||
crafingTickTime = 0;
|
||||
finalTickTime = currentRecipe.getTickTime();
|
||||
neededPower = (int) currentRecipe.getStartEU();
|
||||
hasStartedCrafting = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that reactor can execute recipe provided, e.g. has all inputs and can fit output
|
||||
*
|
||||
* @param recipe FusionReactorRecipe Recipe to validate
|
||||
* @return boolean True if reactor can execute recipe provided
|
||||
*/
|
||||
private boolean validateReactorRecipe(FusionReactorRecipe recipe) {
|
||||
boolean validRecipe = validateReactorRecipeInputs(recipe, inventory.getInvStack(topStackSlot), inventory.getInvStack(bottomStackSlot)) || validateReactorRecipeInputs(recipe, inventory.getInvStack(bottomStackSlot), inventory.getInvStack(topStackSlot));
|
||||
return validRecipe && getSize() >= recipe.getMinSize();
|
||||
}
|
||||
|
||||
private boolean validateReactorRecipeInputs(FusionReactorRecipe recipe, ItemStack slot1, ItemStack slot2) {
|
||||
if (ItemUtils.isItemEqual(slot1, recipe.getTopInput(), true, true)) {
|
||||
if (recipe.getBottomInput() != null) {
|
||||
if (!ItemUtils.isItemEqual(slot2, recipe.getBottomInput(), true, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (canFitStack(recipe.getOutput(), outputStackSlot, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(lastTick == world.getTime()){
|
||||
//Prevent tick accerators, blame obstinate for this.
|
||||
return;
|
||||
}
|
||||
lastTick = world.getTime();
|
||||
|
||||
// Force check every second
|
||||
if (world.getTime() % 20 == 0) {
|
||||
checkCoils();
|
||||
inventory.setChanged();
|
||||
}
|
||||
|
||||
if (coilCount == 0) {
|
||||
resetCrafter();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentRecipe == null && inventory.hasChanged()) {
|
||||
updateCurrentRecipe();
|
||||
}
|
||||
|
||||
if (currentRecipe != null) {
|
||||
if (!hasStartedCrafting && inventory.hasChanged() && !validateReactorRecipe(currentRecipe)) {
|
||||
resetCrafter();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasStartedCrafting) {
|
||||
// Ignition!
|
||||
if (canUseEnergy(currentRecipe.getStartEU())) {
|
||||
useEnergy(currentRecipe.getStartEU());
|
||||
hasStartedCrafting = true;
|
||||
inventory.shrinkSlot(topStackSlot, currentRecipe.getTopInput().getCount());
|
||||
if (!currentRecipe.getBottomInput().isEmpty()) {
|
||||
inventory.shrinkSlot(bottomStackSlot, currentRecipe.getBottomInput().getCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasStartedCrafting && crafingTickTime < finalTickTime) {
|
||||
crafingTickTime++;
|
||||
// Power gen
|
||||
if (currentRecipe.getEuTick() > 0) {
|
||||
// Waste power if it has no where to go
|
||||
addEnergy(currentRecipe.getEuTick() * getPowerMultiplier());
|
||||
powerChange = currentRecipe.getEuTick() * getPowerMultiplier();
|
||||
} else { // Power user
|
||||
if (canUseEnergy(currentRecipe.getEuTick() * -1)) {
|
||||
setEnergy(getEnergy() - currentRecipe.getEuTick() * -1);
|
||||
}
|
||||
}
|
||||
} else if (crafingTickTime >= finalTickTime) {
|
||||
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
|
||||
if (inventory.getInvStack(outputStackSlot).isEmpty()) {
|
||||
inventory.setInvStack(outputStackSlot, currentRecipe.getOutput().copy());
|
||||
} else {
|
||||
inventory.shrinkSlot(outputStackSlot, -currentRecipe.getOutput().getCount());
|
||||
}
|
||||
if (validateReactorRecipe(this.currentRecipe)) {
|
||||
crafingTickTime = 0;
|
||||
inventory.shrinkSlot(topStackSlot, currentRecipe.getTopInput().getCount());
|
||||
if (!currentRecipe.getBottomInput().isEmpty()) {
|
||||
inventory.shrinkSlot(bottomStackSlot, currentRecipe.getBottomInput().getCount());
|
||||
}
|
||||
} else {
|
||||
resetCrafter();
|
||||
}
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
|
||||
inventory.resetChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getPowerMultiplier() {
|
||||
double calc = (1F/2F) * Math.pow(size -5, 1.8);
|
||||
return Math.max(Math.round(calc * 100D) / 100D, 1D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return Math.min(maxEnergy * getPowerMultiplier(), Integer.MAX_VALUE / RebornCoreConfig.euPerFU);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return !(direction == Direction.DOWN || direction == Direction.UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return direction == Direction.DOWN || direction == Direction.UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
if (!hasStartedCrafting) {
|
||||
return 0;
|
||||
}
|
||||
return Integer.MAX_VALUE / RebornCoreConfig.euPerFU;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
if (hasStartedCrafting) {
|
||||
return 0;
|
||||
}
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
this.crafingTickTime = tagCompound.getInt("crafingTickTime");
|
||||
this.finalTickTime = tagCompound.getInt("finalTickTime");
|
||||
this.neededPower = tagCompound.getInt("neededPower");
|
||||
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
|
||||
if(tagCompound.containsKey("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null){
|
||||
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
|
||||
if (validateReactorRecipe(reactorRecipe)) {
|
||||
this.currentRecipe = reactorRecipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(tagCompound.containsKey("size")){
|
||||
this.size = tagCompound.getInt("size");
|
||||
}
|
||||
this.size = Math.min(size, maxCoilSize);//Done here to force the samller size, will be useful if people lag out on a large one.
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tagCompound.putInt("crafingTickTime", this.crafingTickTime);
|
||||
tagCompound.putInt("finalTickTime", this.finalTickTime);
|
||||
tagCompound.putInt("neededPower", this.neededPower);
|
||||
tagCompound.putBoolean("hasStartedCrafting", this.hasStartedCrafting);
|
||||
tagCompound.putBoolean("hasActiveRecipe", this.currentRecipe != null);
|
||||
tagCompound.putInt("size", size);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// TileLegacyMachineBase
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
this.checkCoils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.FUSION_CONTROL_COMPUTER.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<FusionControlComputerBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("fusionreactor").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).syncEnergyValue()
|
||||
.syncIntegerValue(this::getCoilStatus, this::setCoilStatus)
|
||||
.syncIntegerValue(this::getCrafingTickTime, this::setCrafingTickTime)
|
||||
.syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime)
|
||||
.syncIntegerValue(this::getSize, this::setSize)
|
||||
.syncIntegerValue(this::getState, this::setState)
|
||||
.syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
public int getCoilStatus() {
|
||||
return coilCount;
|
||||
}
|
||||
|
||||
public void setCoilStatus(int coilStatus) {
|
||||
this.coilCount = coilStatus;
|
||||
}
|
||||
|
||||
public int getCrafingTickTime() {
|
||||
return crafingTickTime;
|
||||
}
|
||||
|
||||
public void setCrafingTickTime(int crafingTickTime) {
|
||||
this.crafingTickTime = crafingTickTime;
|
||||
}
|
||||
|
||||
public int getFinalTickTime() {
|
||||
return finalTickTime;
|
||||
}
|
||||
|
||||
public void setFinalTickTime(int finalTickTime) {
|
||||
this.finalTickTime = finalTickTime;
|
||||
}
|
||||
|
||||
public int getNeededPower() {
|
||||
return neededPower;
|
||||
}
|
||||
|
||||
public void setNeededPower(int neededPower) {
|
||||
this.neededPower = neededPower;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void changeSize(int sizeDelta){
|
||||
int newSize = size + sizeDelta;
|
||||
this.size = Math.max(6, Math.min(maxCoilSize, newSize));
|
||||
}
|
||||
|
||||
public int getState(){
|
||||
if(currentRecipe == null ){
|
||||
return 0; //No Recipe
|
||||
}
|
||||
if(!hasStartedCrafting){
|
||||
return 1; //Waiting on power
|
||||
}
|
||||
if(hasStartedCrafting){
|
||||
return 2; //Crafting
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setState(int state){
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getStateString(){
|
||||
if(state == -1){
|
||||
return "";
|
||||
} else if (state == 0){
|
||||
return "No recipe";
|
||||
} else if (state == 1){
|
||||
return "Charging";
|
||||
} else if (state == 2){
|
||||
return "Crafting";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import reborncore.fluid.FluidStack;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.api.generator.FluidGeneratorRecipe;
|
||||
import techreborn.api.generator.FluidGeneratorRecipeList;
|
||||
import techreborn.api.generator.GeneratorRecipeHelper;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider {
|
||||
|
||||
private final FluidGeneratorRecipeList recipes;
|
||||
private final int euTick;
|
||||
private FluidGeneratorRecipe currentRecipe;
|
||||
private int ticksSinceLastChange;
|
||||
public final Tank tank;
|
||||
public final RebornInventory<?> inventory;
|
||||
protected long lastOutput = 0;
|
||||
|
||||
/*
|
||||
* We use this to keep track of fractional millibuckets, allowing us to hit
|
||||
* our eu/bucket targets while still only ever removing integer millibucket
|
||||
* amounts.
|
||||
*/
|
||||
double pendingWithdraw = 0.0;
|
||||
|
||||
public BaseFluidGeneratorBlockEntity(BlockEntityType<?> blockEntityType, EFluidGenerator type, String blockEntityName, int tankCapacity, int euTick) {
|
||||
super(blockEntityType);
|
||||
recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type);
|
||||
tank = new Tank(blockEntityName, tankCapacity, this);
|
||||
inventory = new RebornInventory<>(3, blockEntityName, 64, this).withConfiguredAccess();
|
||||
this.euTick = euTick;
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
ticksSinceLastChange++;
|
||||
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
|
||||
// Check cells input slot 2 time per second
|
||||
// Please, keep ticks counting on client also to report progress to GUI
|
||||
if (ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getInvStack(0).isEmpty()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 0, 1);
|
||||
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType());
|
||||
}
|
||||
tank.setBlockEntity(this);
|
||||
tank.compareAndUpdate();
|
||||
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
if (tank.getFluidAmount() > 0) {
|
||||
if (currentRecipe == null || !FluidUtils.fluidEquals(currentRecipe.getFluid(), tank.getFluidType()))
|
||||
currentRecipe = getRecipes().getRecipeForFluid(tank.getFluidType()).orElse(null);
|
||||
|
||||
if (currentRecipe != null) {
|
||||
final Integer euPerBucket = currentRecipe.getEnergyPerMb() * 1000;
|
||||
final float millibucketsPerTick = euTick * 1000 / (float) euPerBucket;
|
||||
|
||||
if (tryAddingEnergy(euTick)) {
|
||||
pendingWithdraw += millibucketsPerTick;
|
||||
final int currentWithdraw = (int) pendingWithdraw;
|
||||
pendingWithdraw -= currentWithdraw;
|
||||
tank.drain(currentWithdraw, true);
|
||||
lastOutput = world.getTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (world.getTime() - lastOutput < 30 && !isActive()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true));
|
||||
}
|
||||
else if (world.getTime() - lastOutput > 30 && isActive()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, false));
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgressScaled(int scale) {
|
||||
if (isActive()){
|
||||
return ticksSinceLastChange * scale;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected boolean tryAddingEnergy(int amount) {
|
||||
if (getMaxPower() - getEnergy() >= amount) {
|
||||
addEnergy(amount);
|
||||
return true;
|
||||
} else if (getMaxPower() - getEnergy() > 0) {
|
||||
addEnergy(getMaxPower() - getEnergy());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean acceptFluid() {
|
||||
if (!inventory.getInvStack(0).isEmpty()) {
|
||||
FluidStack stack = FluidUtils.getFluidStackInContainer(inventory.getInvStack(0));
|
||||
if (stack != null)
|
||||
return recipes.getRecipeForFluid(stack.getFluid()).isPresent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public FluidGeneratorRecipeList getRecipes() {
|
||||
return recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return euTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<?> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
tank.read(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getTicksSinceLastChange() {
|
||||
return ticksSinceLastChange;
|
||||
}
|
||||
|
||||
public void setTicksSinceLastChange(int ticksSinceLastChange) {
|
||||
this.ticksSinceLastChange = ticksSinceLastChange;
|
||||
}
|
||||
|
||||
public int getTankAmount(){
|
||||
return tank.getFluidAmount();
|
||||
}
|
||||
|
||||
public void setTankAmount(int amount){
|
||||
tank.setFluidAmount(amount);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "lightning_rod", key = "LightningRodMaxOutput", comment = "Lightning Rod Max Output (Value in EU)")
|
||||
public static int maxOutput = 2048;
|
||||
@ConfigRegistry(config = "generators", category = "lightning_rod", key = "LightningRodMaxEnergy", comment = "Lightning Rod Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 100_000_000;
|
||||
@ConfigRegistry(config = "generators", category = "lightning_rod", key = "LightningRodChanceOfStrike", comment = "Chance of lightning striking a rod (Range: 0-70)")
|
||||
public static int chanceOfStrike = 24;
|
||||
@ConfigRegistry(config = "generators", category = "lightning_rod", key = "LightningRodBaseStrikeEnergy", comment = "Base amount of energy per strike (Value in EU)")
|
||||
public static int baseEnergyStrike = 262_144;
|
||||
|
||||
private int onStatusHoldTicks = -1;
|
||||
|
||||
public LightningRodBlockEntity() {
|
||||
super(TRBlockEntities.LIGHTNING_ROD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (onStatusHoldTicks > 0)
|
||||
--onStatusHoldTicks;
|
||||
|
||||
if (onStatusHoldTicks == 0 || getEnergy() <= 0) {
|
||||
if (getCachedState().getBlock() instanceof BlockMachineBase)
|
||||
((BlockMachineBase) getCachedState().getBlock()).setActive(false, world, pos);
|
||||
onStatusHoldTicks = -1;
|
||||
}
|
||||
|
||||
final float weatherStrength = world.getThunderGradient(1.0F);
|
||||
if (weatherStrength > 0.2F) {
|
||||
//lightStrikeChance = (MAX - (CHANCE * WEATHER_STRENGTH)
|
||||
final float lightStrikeChance = (100F - chanceOfStrike) * 20F;
|
||||
final float totalChance = lightStrikeChance * getLightningStrikeMultiplier() * (1.1F - weatherStrength);
|
||||
if (world.random.nextInt((int) Math.floor(totalChance)) == 0) {
|
||||
if (!isValidIronFence(pos.up().getY())) {
|
||||
onStatusHoldTicks = 400;
|
||||
return;
|
||||
}
|
||||
final LightningEntity lightningBolt = new LightningEntity(world,
|
||||
pos.getX() + 0.5F, world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, getPos()).getY(),
|
||||
pos.getZ() + 0.5F, false);
|
||||
if(true){
|
||||
throw new RuntimeException("fix me");
|
||||
}
|
||||
//world.addWeatherEffect(lightningBolt);
|
||||
world.spawnEntity(lightningBolt);
|
||||
addEnergy(baseEnergyStrike * (0.3F + weatherStrength));
|
||||
((BlockMachineBase) world.getBlockState(pos).getBlock()).setActive(true, world, pos);
|
||||
onStatusHoldTicks = 400;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float getLightningStrikeMultiplier() {
|
||||
final float actualHeight = 256;
|
||||
final float groundLevel = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, getPos()).getY();
|
||||
for (int i = pos.getY() + 1; i < actualHeight; i++) {
|
||||
if (!isValidIronFence(i)) {
|
||||
if (groundLevel >= i)
|
||||
return 4.3F;
|
||||
final float max = actualHeight - groundLevel;
|
||||
final float got = i - groundLevel;
|
||||
return 1.2F - got / max;
|
||||
}
|
||||
}
|
||||
return 4F;
|
||||
}
|
||||
|
||||
public boolean isValidIronFence(int y) {
|
||||
Block block = this.world.getBlockState(new BlockPos(pos.getX(), y, pos.getZ())).getBlock();
|
||||
if(block == TRContent.REFINED_IRON_FENCE){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.LIGHTNING_ROD.getStack();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class PlasmaGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "plasma_generator", key = "PlasmaGeneratorMaxOutput", comment = "Plasma Generator Max Output (Value in EU)")
|
||||
public static int maxOutput = 2048;
|
||||
@ConfigRegistry(config = "generators", category = "plasma_generator", key = "PlasmaGeneratorMaxEnergy", comment = "Plasma Generator Max Energy (Value in EU)")
|
||||
public static double maxEnergy = 500_000_000;
|
||||
@ConfigRegistry(config = "generators", category = "plasma_generator", key = "PlasmaGeneratorTankCapacity", comment = "Plasma Generator Tank Capacity")
|
||||
public static int tankCapacity = 10_000;
|
||||
@ConfigRegistry(config = "generators", category = "plasma_generator", key = "PlasmaGeneratorEnergyPerTick", comment = "Plasma Generator Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 400;
|
||||
|
||||
public PlasmaGeneratorBlockEntity() {
|
||||
super(TRBlockEntities.PLASMA_GENERATOR, EFluidGenerator.PLASMA, "PlasmaGeneratorBlockEntity", tankCapacity, energyPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.PLASMA_GENERATOR.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("plasmagenerator").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator;
|
||||
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.blocks.generator.BlockSolarPanel;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRContent.SolarPanels;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
|
||||
|
||||
boolean canSeeSky = false;
|
||||
boolean lastState = false;
|
||||
SolarPanels panel;
|
||||
|
||||
public SolarPanelBlockEntity() {
|
||||
super(TRBlockEntities.SOLAR_PANEL);
|
||||
}
|
||||
|
||||
public boolean isSunOut() {
|
||||
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaylight();
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
if (panel == TRContent.SolarPanels.CREATIVE) {
|
||||
checkOverfill = false;
|
||||
setEnergy(Integer.MAX_VALUE);
|
||||
return;
|
||||
}
|
||||
if (world.getTime() % 20 == 0) {
|
||||
canSeeSky = world.method_8626(pos.up());
|
||||
if (lastState != isSunOut()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockSolarPanel.ACTIVE, isSunOut()));
|
||||
lastState = isSunOut();
|
||||
}
|
||||
}
|
||||
int powerToAdd;
|
||||
if (isSunOut()) {
|
||||
powerToAdd = panel.generationRateD;
|
||||
} else if (canSeeSky) {
|
||||
powerToAdd = panel.generationRateN;
|
||||
} else {
|
||||
powerToAdd = 0;
|
||||
}
|
||||
|
||||
addEnergy(powerToAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return panel.internalCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return panel.generationRateD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumPowerTier getTier() {
|
||||
return panel.powerTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTier() {
|
||||
// Nope
|
||||
}
|
||||
|
||||
// TODO: Translate
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
info.add(new LiteralText(Formatting.GRAY + "Internal Energy Storage: " + Formatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted((int) getMaxPower())));
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + "Generation Rate Day: " + Formatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(panel.generationRateD)));
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + "Generation Rate Night: " + Formatting.GOLD
|
||||
+ PowerSystem.getLocaliszedPowerFormatted(panel.generationRateN)));
|
||||
|
||||
info.add(new LiteralText(Formatting.GRAY + "Tier: " + Formatting.GOLD
|
||||
+ StringUtils.toFirstCapitalAllLowercase(getTier().toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tag) {
|
||||
if (world == null) {
|
||||
// We are in BlockEntity.create method during chunk load.
|
||||
this.checkOverfill = false;
|
||||
}
|
||||
super.fromTag(tag);
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
Block panelBlock = world.getBlockState(pos).getBlock();
|
||||
if (panelBlock instanceof BlockSolarPanel) {
|
||||
BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock;
|
||||
panel = solarPanelBlock.panelType;
|
||||
}
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity playerIn) {
|
||||
return new ItemStack(getBlockType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.advanced;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class DieselGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "diesel_generator", key = "DieselGeneratorMaxOutput", comment = "Diesel Generator Max Output (Value in EU)")
|
||||
public static int maxOutput = 128;
|
||||
@ConfigRegistry(config = "generators", category = "diesel_generator", key = "DieselGeneratorMaxEnergy", comment = "Diesel Generator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1_000_000;
|
||||
@ConfigRegistry(config = "generators", category = "diesel_generator", key = "DieselGeneratorTankCapacity", comment = "Diesel Generator Tank Capacity")
|
||||
public static int tankCapacity = 10_000;
|
||||
@ConfigRegistry(config = "generators", category = "diesel_generator", key = "DieselGeneratorEnergyPerTick", comment = "Diesel Generator Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 20;
|
||||
|
||||
public DieselGeneratorBlockEntity() {
|
||||
super(TRBlockEntities.DIESEL_GENERATOR, EFluidGenerator.DIESEL, "DieselGeneratorBlockEntity", tankCapacity, energyPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.DIESEL_GENERATOR.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("dieselgenerator").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.advanced;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "dragon_egg_siphoner", key = "DragonEggSiphonerMaxOutput", comment = "Dragon Egg Siphoner Max Output (Value in EU)")
|
||||
public static int maxOutput = 128;
|
||||
@ConfigRegistry(config = "generators", category = "dragon_egg_siphoner", key = "DragonEggSiphonerMaxEnergy", comment = "Dragon Egg Siphoner Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000;
|
||||
@ConfigRegistry(config = "generators", category = "dragon_egg_siphoner", key = "DragonEggSiphonerEnergyPerTick", comment = "Dragon Egg Siphoner Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 4;
|
||||
|
||||
public RebornInventory<DragonEggSyphonBlockEntity> inventory = new RebornInventory<>(3, "DragonEggSyphonBlockEntity", 64, this).withConfiguredAccess();
|
||||
private long lastOutput = 0;
|
||||
|
||||
public DragonEggSyphonBlockEntity() {
|
||||
super(TRBlockEntities.DRAGON_EGG_SYPHON);
|
||||
}
|
||||
|
||||
private boolean tryAddingEnergy(int amount) {
|
||||
if (this.getMaxPower() - this.getEnergy() >= amount) {
|
||||
addEnergy(amount);
|
||||
return true;
|
||||
} else if (this.getMaxPower() - this.getEnergy() > 0) {
|
||||
addEnergy(this.getMaxPower() - this.getEnergy());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (!world.isClient) {
|
||||
if (world.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))
|
||||
.getBlock() == Blocks.DRAGON_EGG) {
|
||||
if (tryAddingEnergy(energyPerTick))
|
||||
lastOutput = world.getTime();
|
||||
}
|
||||
|
||||
if (world.getTime() - lastOutput < 30 && !isActive()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true));
|
||||
} else if (world.getTime() - lastOutput > 30 && isActive()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.DRAGON_EGG_SYPHON.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<DragonEggSyphonBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.advanced;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class GasTurbineBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "gas_generator", key = "GasGeneratorMaxOutput", comment = "Gas Generator Max Output (Value in EU)")
|
||||
public static int maxOutput = 128;
|
||||
@ConfigRegistry(config = "generators", category = "gas_generator", key = "GasGeneratorMaxEnergy", comment = "Gas Generator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000000;
|
||||
@ConfigRegistry(config = "generators", category = "gas_generator", key = "GasGeneratorTankCapacity", comment = "Gas Generator Tank Capacity")
|
||||
public static int tankCapacity = 10000;
|
||||
@ConfigRegistry(config = "generators", category = "gas_generator", key = "GasGeneratorEnergyPerTick", comment = "Gas Generator Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 16;
|
||||
|
||||
public GasTurbineBlockEntity() {
|
||||
super(TRBlockEntities.GAS_TURBINE, EFluidGenerator.GAS, "GasTurbineBlockEntity", tankCapacity, energyPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.GAS_TURBINE.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("gasturbine").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.advanced;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class SemiFluidGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "semifluid_generator", key = "SemifluidGeneratorMaxOutput", comment = "Semifluid Generator Max Output (Value in EU)")
|
||||
public static int maxOutput = 128;
|
||||
@ConfigRegistry(config = "generators", category = "semifluid_generator", key = "SemifluidGeneratorMaxEnergy", comment = "Semifluid Generator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000000;
|
||||
@ConfigRegistry(config = "generators", category = "semifluid_generator", key = "SemifluidGeneratorTankCapacity", comment = "Semifluid Generator Tank Capacity")
|
||||
public static int tankCapacity = 10000;
|
||||
@ConfigRegistry(config = "generators", category = "semifluid_generator", key = "SemifluidGeneratorEnergyPerTick", comment = "Semifluid Generator Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 8;
|
||||
|
||||
public SemiFluidGeneratorBlockEntity() {
|
||||
super(TRBlockEntities.SEMI_FLUID_GENERATOR, EFluidGenerator.SEMIFLUID, "SemiFluidGeneratorBlockEntity", tankCapacity, energyPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.SEMI_FLUID_GENERATOR.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("semifluidgenerator").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.advanced;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.generator.EFluidGenerator;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ThermalGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "thermal_generator", key = "ThermalGeneratorMaxOutput", comment = "Thermal Generator Max Output (Value in EU)")
|
||||
public static int maxOutput = 128;
|
||||
@ConfigRegistry(config = "generators", category = "thermal_generator", key = "ThermalGeneratorMaxEnergy", comment = "Thermal Generator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1_000_000;
|
||||
@ConfigRegistry(config = "generators", category = "thermal_generator", key = "ThermalGeneratorTankCapacity", comment = "Thermal Generator Tank Capacity")
|
||||
public static int tankCapacity = 10_000;
|
||||
@ConfigRegistry(config = "generators", category = "thermal_generator", key = "ThermalGeneratorEnergyPerTick", comment = "Thermal Generator Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 16;
|
||||
|
||||
public ThermalGeneratorBlockEntity() {
|
||||
super(TRBlockEntities.THERMAL_GEN, EFluidGenerator.THERMAL, "ThermalGeneratorBlockEntity", tankCapacity, energyPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.THERMAL_GENERATOR.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("thermalgenerator").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.basic;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.FurnaceBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "generator", key = "GeneratorMaxOutput", comment = "Solid Fuel Generator Max Output (Value in EU)")
|
||||
public static int maxOutput = 32;
|
||||
@ConfigRegistry(config = "generators", category = "generator", key = "GeneratorMaxEnergy", comment = "Solid Fuel Generator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
@ConfigRegistry(config = "generators", category = "generator", key = "GeneratorEnergyOutput", comment = "Solid Fuel Generator Energy Output Amount (Value in EU)")
|
||||
public static int outputAmount = 10;
|
||||
|
||||
public RebornInventory<SolidFuelGeneratorBlockEntity> inventory = new RebornInventory<>(2, "SolidFuelGeneratorBlockEntity", 64, this).withConfiguredAccess();
|
||||
public int fuelSlot = 0;
|
||||
public int burnTime;
|
||||
public int totalBurnTime = 0;
|
||||
// sould properly use the conversion
|
||||
// ratio here.
|
||||
public boolean isBurning;
|
||||
public boolean lastTickBurning;
|
||||
ItemStack burnItem;
|
||||
|
||||
public SolidFuelGeneratorBlockEntity() {
|
||||
super(TRBlockEntities.SOLID_FUEL_GENEREATOR);
|
||||
}
|
||||
|
||||
public static int getItemBurnTime(ItemStack stack) {
|
||||
return FurnaceBlockEntity.createFuelTimeMap().get(stack) / 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
if (getEnergy() < getMaxPower()) {
|
||||
if (burnTime > 0) {
|
||||
burnTime--;
|
||||
addEnergy(SolidFuelGeneratorBlockEntity.outputAmount);
|
||||
isBurning = true;
|
||||
}
|
||||
} else {
|
||||
isBurning = false;
|
||||
}
|
||||
|
||||
if (burnTime == 0) {
|
||||
updateState();
|
||||
burnTime = totalBurnTime = SolidFuelGeneratorBlockEntity.getItemBurnTime(inventory.getInvStack(fuelSlot));
|
||||
if (burnTime > 0) {
|
||||
updateState();
|
||||
burnItem = inventory.getInvStack(fuelSlot);
|
||||
if (inventory.getInvStack(fuelSlot).getCount() == 1) {
|
||||
if (inventory.getInvStack(fuelSlot).getItem() == Items.LAVA_BUCKET || inventory.getInvStack(fuelSlot).getItem() instanceof BucketItem) {
|
||||
inventory.setInvStack(fuelSlot, new ItemStack(Items.BUCKET));
|
||||
} else {
|
||||
inventory.setInvStack(fuelSlot, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
} else {
|
||||
inventory.shrinkSlot(fuelSlot, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastTickBurning = isBurning;
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
final BlockState BlockStateContainer = world.getBlockState(pos);
|
||||
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
|
||||
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
|
||||
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != burnTime > 0) {
|
||||
blockMachineBase.setActive(burnTime > 0, world, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.SOLID_FUEL_GENERATOR.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<SolidFuelGeneratorBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return burnTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(final int burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
public int getTotalBurnTime() {
|
||||
return totalBurnTime;
|
||||
}
|
||||
|
||||
public void setTotalBurnTime(final int totalBurnTime) {
|
||||
this.totalBurnTime = totalBurnTime;
|
||||
}
|
||||
|
||||
public int getScaledBurnTime(final int i) {
|
||||
return (int) ((float) burnTime / (float) totalBurnTime * i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("generator").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).fuelSlot(0, 80, 54).energySlot(1, 8, 72).syncEnergyValue()
|
||||
.syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.basic;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.blocks.generator.BlockWindMill;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 25/02/2016.
|
||||
*/
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class WaterMillBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "water_mill", key = "WaterMillMaxOutput", comment = "Water Mill Max Output (Value in EU)")
|
||||
public static int maxOutput = 32;
|
||||
@ConfigRegistry(config = "generators", category = "water_mill", key = "WaterMillMaxEnergy", comment = "Water Mill Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000;
|
||||
@ConfigRegistry(config = "generators", category = "water_mill", key = "WaterMillEnergyPerTick", comment = "Water Mill Energy Multiplier")
|
||||
public static double energyMultiplier = 0.1;
|
||||
|
||||
int waterblocks = 0;
|
||||
|
||||
public WaterMillBlockEntity() {
|
||||
super(TRBlockEntities.WATER_MILL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.getTime() % 20 == 0) {
|
||||
checkForWater();
|
||||
}
|
||||
if (waterblocks > 0) {
|
||||
addEnergy(waterblocks * energyMultiplier);
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockWindMill.ACTIVE, true));
|
||||
}
|
||||
else {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockWindMill.ACTIVE, false));
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForWater() {
|
||||
waterblocks = 0;
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (facing.getAxis().isHorizontal() && world.getBlockState(pos.offset(facing)).getBlock() == Blocks.WATER) {
|
||||
waterblocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.WATER_MILL.getStack();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.generator.basic;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 25/02/2016.
|
||||
*/
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class WindMillBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
|
||||
|
||||
@ConfigRegistry(config = "generators", category = "wind_mill", key = "WindMillMaxOutput", comment = "Wind Mill Max Output (Value in EU)")
|
||||
public static int maxOutput = 128;
|
||||
@ConfigRegistry(config = "generators", category = "wind_mill", key = "WindMillMaxEnergy", comment = "Wind Mill Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
@ConfigRegistry(config = "generators", category = "wind_mill", key = "WindMillEnergyPerTick", comment = "Wind Mill Energy Per Tick (Value in EU)")
|
||||
public static int baseEnergy = 2;
|
||||
@ConfigRegistry(config = "generators", category = "wind_mill", key = "WindMillThunderMultiplier", comment = "Wind Mill Thunder Multiplier")
|
||||
public static double thunderMultiplier = 1.25;
|
||||
|
||||
public WindMillBlockEntity() {
|
||||
super(TRBlockEntities.WIND_MILL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (pos.getY() > 64) {
|
||||
int actualPower = baseEnergy;
|
||||
if (world.isThundering()) {
|
||||
actualPower *= thunderMultiplier;
|
||||
}
|
||||
addEnergy(actualPower); // Value taken from
|
||||
// http://wiki.industrial-craft.net/?title=Wind_Mill
|
||||
// Not worth making more complicated
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.WIND_MILL.getStack();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.lighting;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import techreborn.blocks.lighting.BlockLamp;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
public class LampBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop {
|
||||
|
||||
private static int capacity = 33;
|
||||
|
||||
public LampBlockEntity() {
|
||||
super(TRBlockEntities.LAMP);
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world == null || world.isClient) {
|
||||
return;
|
||||
}
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block b = state.getBlock();
|
||||
if (b instanceof BlockLamp) {
|
||||
double cost = getEuPerTick(((BlockLamp) b).getCost());
|
||||
if (getEnergy() > cost) {
|
||||
useEnergy(getEuPerTick(cost));
|
||||
if (!BlockLamp.isActive(state))
|
||||
BlockLamp.setActive(true, world, pos);
|
||||
} else if (BlockLamp.isActive(state)) {
|
||||
BlockLamp.setActive(false, world, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
Direction me = BlockLamp.getFacing(world.getBlockState(pos)).getOpposite();
|
||||
return direction == me;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return 32;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return new ItemStack(world.getBlockState(pos).getBlock());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,291 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.iron;
|
||||
|
||||
import net.minecraft.block.entity.FurnaceBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.crafting.RebornIngredient;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
public int tickTime;
|
||||
public RebornInventory<IronAlloyFurnaceBlockEntity> inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this).withConfiguredAccess();
|
||||
public int burnTime;
|
||||
public int currentItemBurnTime;
|
||||
public int cookTime;
|
||||
int input1 = 0;
|
||||
int input2 = 1;
|
||||
int output = 2;
|
||||
int fuel = 3;
|
||||
|
||||
public IronAlloyFurnaceBlockEntity() {
|
||||
super(TRBlockEntities.IRON_ALLOY_FURNACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of ticks that the supplied fuel item will keep the
|
||||
* furnace burning, or 0 if the item isn't fuel
|
||||
* @param stack Itemstack of fuel
|
||||
* @return Integer Number of ticks
|
||||
*/
|
||||
public static int getItemBurnTime(ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return FurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
final boolean flag = this.burnTime > 0;
|
||||
boolean flag1 = false;
|
||||
if (this.burnTime > 0) {
|
||||
--this.burnTime;
|
||||
}
|
||||
if (!this.world.isClient) {
|
||||
if (this.burnTime != 0 || !inventory.getInvStack(this.input1).isEmpty()&& !inventory.getInvStack(this.fuel).isEmpty()) {
|
||||
if (this.burnTime == 0 && this.canSmelt()) {
|
||||
this.currentItemBurnTime = this.burnTime = IronAlloyFurnaceBlockEntity.getItemBurnTime(inventory.getInvStack(this.fuel));
|
||||
if (this.burnTime > 0) {
|
||||
flag1 = true;
|
||||
if (!inventory.getInvStack(this.fuel).isEmpty()) {
|
||||
inventory.shrinkSlot(this.fuel, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.isBurning() && this.canSmelt()) {
|
||||
++this.cookTime;
|
||||
if (this.cookTime == 200) {
|
||||
this.cookTime = 0;
|
||||
this.smeltItem();
|
||||
flag1 = true;
|
||||
}
|
||||
} else {
|
||||
this.cookTime = 0;
|
||||
}
|
||||
}
|
||||
if (flag != this.burnTime > 0) {
|
||||
flag1 = true;
|
||||
// TODO sync on/off
|
||||
}
|
||||
}
|
||||
if (flag1) {
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAllInputs(final RebornRecipe recipeType) {
|
||||
if (recipeType == null) {
|
||||
return false;
|
||||
}
|
||||
for (RebornIngredient ingredient : recipeType.getRebornIngredients()) {
|
||||
boolean hasItem = false;
|
||||
for (int inputslot = 0; inputslot < 2; inputslot++) {
|
||||
if (ingredient.test(inventory.getInvStack(inputslot))) {
|
||||
hasItem = true;
|
||||
}
|
||||
}
|
||||
if (!hasItem)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean canSmelt() {
|
||||
if (inventory.getInvStack(this.input1).isEmpty() || inventory.getInvStack(this.input2).isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
ItemStack itemstack = null;
|
||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
||||
if (this.hasAllInputs(recipeType)) {
|
||||
itemstack = recipeType.getOutputs().get(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemstack == null)
|
||||
return false;
|
||||
if (inventory.getInvStack(this.output).isEmpty())
|
||||
return true;
|
||||
if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack))
|
||||
return false;
|
||||
final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount();
|
||||
return result <= inventory.getStackLimit() && result <= inventory.getInvStack(this.output).getMaxCount(); // Forge
|
||||
// BugFix:
|
||||
// Make
|
||||
// it
|
||||
// respect
|
||||
// stack
|
||||
// sizes
|
||||
// properly.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn one item from the furnace source stack into the appropriate smelted
|
||||
* item in the furnace result stack
|
||||
*/
|
||||
public void smeltItem() {
|
||||
if (this.canSmelt()) {
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
||||
if (this.hasAllInputs(recipeType)) {
|
||||
itemstack = recipeType.getOutputs().get(0);
|
||||
break;
|
||||
}
|
||||
if (!itemstack.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.getInvStack(this.output).isEmpty()) {
|
||||
inventory.setInvStack(this.output, itemstack.copy());
|
||||
} else if (inventory.getInvStack(this.output).getItem() == itemstack.getItem()) {
|
||||
inventory.shrinkSlot(this.output, -itemstack.getCount());
|
||||
}
|
||||
|
||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
||||
boolean hasAllRecipes = true;
|
||||
if (this.hasAllInputs(recipeType)) {
|
||||
|
||||
} else {
|
||||
hasAllRecipes = false;
|
||||
}
|
||||
if (hasAllRecipes) {
|
||||
for (RebornIngredient ingredient : recipeType.getRebornIngredients()) {
|
||||
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
|
||||
if (ingredient.test(this.inventory.getInvStack(inputSlot))) {
|
||||
inventory.shrinkSlot(inputSlot, ingredient.getSize());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Furnace isBurning
|
||||
* @return Boolean True if furnace is burning
|
||||
*/
|
||||
public boolean isBurning() {
|
||||
return this.burnTime > 0;
|
||||
}
|
||||
|
||||
public int getBurnTimeRemainingScaled(final int scale) {
|
||||
if (this.currentItemBurnTime == 0) {
|
||||
this.currentItemBurnTime = 200;
|
||||
}
|
||||
|
||||
return this.burnTime * scale / this.currentItemBurnTime;
|
||||
}
|
||||
|
||||
public int getCookProgressScaled(final int scale) {
|
||||
return this.cookTime * scale / 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getFacing() {
|
||||
return this.getFacingEnum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.IRON_ALLOY_FURNACE.getStack();
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<IronAlloyFurnaceBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
|
||||
public int getBurnTime() {
|
||||
return this.burnTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(final int burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
public int getCurrentItemBurnTime() {
|
||||
return this.currentItemBurnTime;
|
||||
}
|
||||
|
||||
public void setCurrentItemBurnTime(final int currentItemBurnTime) {
|
||||
this.currentItemBurnTime = currentItemBurnTime;
|
||||
}
|
||||
|
||||
public int getCookTime() {
|
||||
return this.cookTime;
|
||||
}
|
||||
|
||||
public void setCookTime(final int cookTime) {
|
||||
this.cookTime = cookTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("alloyfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
||||
.addInventory().blockEntity(this)
|
||||
.filterSlot(0, 47, 17,
|
||||
stack -> ModRecipes.ALLOY_SMELTER.getRecipes(player.world).stream().anyMatch(recipe -> recipe.getRebornIngredients().get(0).test(stack)))
|
||||
.filterSlot(1, 65, 17,
|
||||
stack -> ModRecipes.ALLOY_SMELTER.getRecipes(player.world).stream().anyMatch(recipe -> recipe.getRebornIngredients().get(1).test(stack)))
|
||||
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53).syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||
.syncIntegerValue(this::getCookTime, this::setCookTime)
|
||||
.syncIntegerValue(this::getCurrentItemBurnTime, this::setCurrentItemBurnTime).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.iron;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.FurnaceBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.events.TRRecipeHandler;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IContainerProvider {
|
||||
|
||||
public int tickTime;
|
||||
public RebornInventory<IronFurnaceBlockEntity> inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this, getInvetoryAccess());
|
||||
public int fuel;
|
||||
public int fuelGague;
|
||||
public int progress;
|
||||
public int fuelScale = 160;
|
||||
int input1 = 0;
|
||||
int output = 1;
|
||||
int fuelslot = 2;
|
||||
boolean active = false;
|
||||
|
||||
public IronFurnaceBlockEntity() {
|
||||
super(TRBlockEntities.IRON_FURNACE);
|
||||
}
|
||||
|
||||
public int gaugeProgressScaled(final int scale) {
|
||||
return this.progress * scale / this.fuelScale;
|
||||
}
|
||||
|
||||
public int gaugeFuelScaled(final int scale) {
|
||||
if (this.fuelGague == 0) {
|
||||
this.fuelGague = this.fuel;
|
||||
if (this.fuelGague == 0) {
|
||||
this.fuelGague = this.fuelScale;
|
||||
}
|
||||
}
|
||||
return this.fuel * scale / this.fuelGague;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if(world.isClient){
|
||||
return;
|
||||
}
|
||||
final boolean burning = this.isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (this.fuel > 0) {
|
||||
this.fuel--;
|
||||
this.updateState();
|
||||
}
|
||||
if (this.fuel <= 0 && this.canSmelt()) {
|
||||
this.fuel = this.fuelGague = (int) (FurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(this.fuelslot).getItem(), 0) * 1.25);
|
||||
if (this.fuel > 0) {
|
||||
// Fuel slot
|
||||
ItemStack fuelStack = inventory.getInvStack(this.fuelslot);
|
||||
if (fuelStack.getItem().hasRecipeRemainder()) {
|
||||
inventory.setInvStack(this.fuelslot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
|
||||
} else if (fuelStack.getCount() > 1) {
|
||||
inventory.shrinkSlot(this.fuelslot, 1);
|
||||
} else if (fuelStack.getCount() == 1) {
|
||||
inventory.setInvStack(this.fuelslot, ItemStack.EMPTY);
|
||||
}
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
if (this.isBurning() && this.canSmelt()) {
|
||||
this.progress++;
|
||||
if (this.progress >= this.fuelScale) {
|
||||
this.progress = 0;
|
||||
this.cookItems();
|
||||
updateInventory = true;
|
||||
}
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
if (burning != this.isBurning()) {
|
||||
updateInventory = true;
|
||||
}
|
||||
if (updateInventory) {
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void cookItems() {
|
||||
if (this.canSmelt()) {
|
||||
final ItemStack itemstack = TRRecipeHandler.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(this.input1));
|
||||
|
||||
if (inventory.getInvStack(this.output).isEmpty()) {
|
||||
inventory.setInvStack(this.output, itemstack.copy());
|
||||
} else if (inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack)) {
|
||||
inventory.getInvStack(this.output).increment(itemstack.getCount());
|
||||
}
|
||||
if (inventory.getInvStack(this.input1).getCount() > 1) {
|
||||
inventory.shrinkSlot(this.input1, 1);
|
||||
} else {
|
||||
inventory.setInvStack(this.input1, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canSmelt() {
|
||||
if (inventory.getInvStack(this.input1).isEmpty())
|
||||
return false;
|
||||
final ItemStack itemstack = TRRecipeHandler.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(this.input1));
|
||||
if (itemstack.isEmpty())
|
||||
return false;
|
||||
if (inventory.getInvStack(this.output).isEmpty())
|
||||
return true;
|
||||
if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack))
|
||||
return false;
|
||||
final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount();
|
||||
return result <= inventory.getStackLimit() && result <= itemstack.getMaxCount();
|
||||
}
|
||||
|
||||
public boolean isBurning() {
|
||||
return this.fuel > 0;
|
||||
}
|
||||
|
||||
public ItemStack getResultFor(final ItemStack stack) {
|
||||
final ItemStack result = TRRecipeHandler.getMatchingRecipes(world, RecipeType.SMELTING, stack);
|
||||
if (!result.isEmpty()) {
|
||||
return result.copy();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
final BlockState BlockStateContainer = this.world.getBlockState(this.pos);
|
||||
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
|
||||
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
|
||||
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != this.fuel > 0)
|
||||
blockMachineBase.setActive(this.fuel > 0, this.world, this.pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<IronFurnaceBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
public static IInventoryAccess<IronFurnaceBlockEntity> getInvetoryAccess(){
|
||||
return (slotID, stack, face, direction, blockEntity) -> {
|
||||
if(direction == IInventoryAccess.AccessDirection.INSERT){
|
||||
boolean isFuel = FurnaceBlockEntity.canUseAsFuel(stack);
|
||||
if(isFuel){
|
||||
ItemStack fuelSlotStack = blockEntity.inventory.getInvStack(blockEntity.fuelslot);
|
||||
if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxCount() != fuelSlotStack.getCount()){
|
||||
return slotID == blockEntity.fuelslot;
|
||||
}
|
||||
}
|
||||
return slotID != blockEntity.output;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return this.fuel;
|
||||
}
|
||||
|
||||
public void setBurnTime(final int burnTime) {
|
||||
this.fuel = burnTime;
|
||||
}
|
||||
|
||||
public int getTotalBurnTime() {
|
||||
return this.fuelGague;
|
||||
}
|
||||
|
||||
public void setTotalBurnTime(final int totalBurnTime) {
|
||||
this.fuelGague = totalBurnTime;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("ironfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
||||
.addInventory().blockEntity(this).fuelSlot(2, 56, 53).slot(0, 56, 17).outputSlot(1, 116, 35)
|
||||
.syncIntegerValue(this::getBurnTime, this::setBurnTime)
|
||||
.syncIntegerValue(this::getProgress, this::setProgress)
|
||||
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class DistillationTowerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "Distillation_tower", key = "DistillationTowerMaxInput", comment = "Distillation Tower Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "Distillation_tower", key = "DistillationTowerMaxEnergy", comment = "Distillation Tower Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public DistillationTowerBlockEntity() {
|
||||
super(TRBlockEntities.DISTILLATION_TOWER, "DistillationTower", maxInput, maxEnergy, TRContent.Machine.DISTILLATION_TOWER.block, 6);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3, 4, 5 };
|
||||
this.inventory = new RebornInventory<>(7, "DistillationTowerBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.DISTILLATION_TOWER, this, 2, 4, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
public boolean getMutliBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 1, 0));
|
||||
final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0));
|
||||
final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, 3, 0));
|
||||
final Material centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getMaterial();
|
||||
final Material centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getMaterial();
|
||||
final boolean center1 = (centerBlock1 == Material.AIR);
|
||||
final boolean center2 = (centerBlock2 == Material.AIR);
|
||||
return layer0 && layer1 && layer2 && layer3 && center1 && center2;
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
if (!world.isClient && getMutliBlock()){
|
||||
super.tick();
|
||||
}
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("Distillationtower").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 35, 27).slot(1, 35, 47).outputSlot(2, 79, 37).outputSlot(3, 99, 37)
|
||||
.outputSlot(4, 119, 37).outputSlot(5, 139, 37).energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue()
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.fluidreplicator.FluidReplicatorRecipeCrafter;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author drcrazy
|
||||
*
|
||||
*/
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "fluidreplicator", key = "FluidReplicatorMaxInput", comment = "Fluid Replicator Max Input (Value in EU)")
|
||||
public static int maxInput = 256;
|
||||
@ConfigRegistry(config = "machines", category = "fluidreplicator", key = "FluidReplicatorMaxEnergy", comment = "Fluid Replicator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 400_000;
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
public static final int TANK_CAPACITY = 16_000;
|
||||
public Tank tank;
|
||||
int ticksSinceLastChange;
|
||||
|
||||
public FluidReplicatorBlockEntity() {
|
||||
super(TRBlockEntities.FLUID_REPLICATOR, "FluidReplicator", maxInput, maxEnergy, TRContent.Machine.FLUID_REPLICATOR.block, 3);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
this.inventory = new RebornInventory<>(4, "FluidReplicatorBlockEntity", 64, this, getInventoryAccess());
|
||||
this.crafter = new FluidReplicatorRecipeCrafter(this, this.inventory, inputs, null);
|
||||
this.tank = new Tank("FluidReplicatorBlockEntity", FluidReplicatorBlockEntity.TANK_CAPACITY, this);
|
||||
}
|
||||
|
||||
public boolean getMultiBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean ring = multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING,
|
||||
MultiblockChecker.ZERO_OFFSET);
|
||||
return ring;
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 2, tank.getFluidType());
|
||||
}
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
if (getMultiBlock()) {
|
||||
super.tick();
|
||||
}
|
||||
|
||||
tank.compareAndUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeCrafter getRecipeCrafter() {
|
||||
return (RecipeCrafter) crafter;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
tank.read(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
private static IInventoryAccess<FluidReplicatorBlockEntity> getInventoryAccess(){
|
||||
return (slotID, stack, face, direction, blockEntity) -> {
|
||||
if(slotID == 0){
|
||||
return stack.isItemEqualIgnoreDamage(TRContent.Parts.UU_MATTER.getStack());
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Nullable
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
|
||||
return new ContainerBuilder("fluidreplicator").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).fluidSlot(1, 124, 35).filterSlot(0, 55, 45, stack -> stack.isItemEqualIgnoreDamage(TRContent.Parts.UU_MATTER.getStack()))
|
||||
.outputSlot(2, 124, 55).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory()
|
||||
.create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "implosion_compressor", key = "ImplosionCompressorMaxInput", comment = "Implosion Compressor Max Input (Value in EU)")
|
||||
public static int maxInput = 64;
|
||||
@ConfigRegistry(config = "machines", category = "implosion_compressor", key = "ImplosionCompressorMaxEnergy", comment = "Implosion Compressor Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 64_000;
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public ImplosionCompressorBlockEntity() {
|
||||
super(TRBlockEntities.IMPLOSION_COMPRESSOR, "ImplosionCompressor", maxInput, maxEnergy, TRContent.Machine.IMPLOSION_COMPRESSOR.block, 4);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3 };
|
||||
this.inventory = new RebornInventory<>(5, "ImplosionCompressorBlockEntity", 64, this);
|
||||
this.crafter = new RecipeCrafter(ModRecipes.IMPLOSION_COMPRESSOR, this, 2, 2, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
public boolean getMutliBlock() {
|
||||
if(multiblockChecker == null){
|
||||
return false;
|
||||
}
|
||||
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 2, 0));
|
||||
final boolean chamber = multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0));
|
||||
return down && chamber && up;
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
multiblockChecker = new MultiblockChecker(world, pos.down(3));
|
||||
}
|
||||
|
||||
if (!world.isClient && getMutliBlock()){
|
||||
super.tick();
|
||||
}
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("implosioncompressor").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 50, 27).slot(1, 50, 47).outputSlot(2, 92, 36).outputSlot(3, 110, 36)
|
||||
.energySlot(4, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.multiblock.IMultiblockPart;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.blocks.BlockMachineCasing;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.multiblocks.MultiBlockCasing;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.MachineCasingBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class IndustrialBlastFurnaceBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "industrial_furnace", key = "IndustrialFurnaceMaxInput", comment = "Industrial Blast Furnace Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "industrial_furnace", key = "IndustrialFurnaceMaxEnergy", comment = "Industrial Blast Furnace Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 40_000;
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
private int cachedHeat;
|
||||
|
||||
public IndustrialBlastFurnaceBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_BLAST_FURNACE, "IndustrialBlastFurnace", maxInput, maxEnergy, TRContent.Machine.INDUSTRIAL_BLAST_FURNACE.block, 4);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3 };
|
||||
this.inventory = new RebornInventory<>(5, "IndustrialBlastFurnaceBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.BLAST_FURNACE, this, 2, 2, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
public int getHeat() {
|
||||
if (!getMutliBlock()){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Bottom center of multiblock
|
||||
final BlockPos location = pos.offset(getFacing().getOpposite(), 2);
|
||||
final BlockEntity blockEntity = world.getBlockEntity(location);
|
||||
|
||||
if (blockEntity instanceof MachineCasingBlockEntity) {
|
||||
if (((MachineCasingBlockEntity) blockEntity).isConnected()
|
||||
&& ((MachineCasingBlockEntity) blockEntity).getMultiblockController().isAssembled()) {
|
||||
final MultiBlockCasing casing = ((MachineCasingBlockEntity) blockEntity).getMultiblockController();
|
||||
|
||||
int heat = 0;
|
||||
|
||||
// Bottom center shouldn't have any blockEntity entities below it
|
||||
if (world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ()))
|
||||
.getBlock() == blockEntity.getWorld().getBlockState(blockEntity.getPos()).getBlock()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (final IMultiblockPart part : casing.connectedParts) {
|
||||
heat += BlockMachineCasing.getHeatFromState(part.getCachedState());
|
||||
}
|
||||
|
||||
if (world.getBlockState(location.offset(Direction.UP, 1)).getBlock().getTranslationKey().equals("blockEntity.lava")
|
||||
&& world.getBlockState(location.offset(Direction.UP, 2)).getBlock().getTranslationKey().equals("blockEntity.lava")) {
|
||||
heat += 500;
|
||||
}
|
||||
return heat;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getMutliBlock() {
|
||||
if(multiblockChecker == null){
|
||||
return false;
|
||||
}
|
||||
final boolean layer0 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean layer1 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 1, 0));
|
||||
final boolean layer2 = multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 2, 0));
|
||||
final boolean layer3 = multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_ANY, new BlockPos(0, 3, 0));
|
||||
final Material centerBlock1 = multiblockChecker.getBlock(0, 1, 0).getMaterial();
|
||||
final Material centerBlock2 = multiblockChecker.getBlock(0, 2, 0).getMaterial();
|
||||
final boolean center1 = (centerBlock1 == Material.AIR || centerBlock1 == Material.LAVA);
|
||||
final boolean center2 = (centerBlock2 == Material.AIR || centerBlock2 == Material.LAVA);
|
||||
return layer0 && layer1 && layer2 && layer3 && center1 && center2;
|
||||
}
|
||||
|
||||
public void setHeat(final int heat) {
|
||||
cachedHeat = heat;
|
||||
}
|
||||
|
||||
public int getCachedHeat() {
|
||||
return cachedHeat;
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2);
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
if (getMutliBlock()){
|
||||
super.tick();
|
||||
}
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("blastfurnace").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 50, 27).slot(1, 50, 47).outputSlot(2, 93, 37).outputSlot(3, 113, 37)
|
||||
.energySlot(4, 8, 72).syncEnergyValue().syncCrafterValue()
|
||||
.syncIntegerValue(this::getHeat, this::setHeat).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity implements IContainerProvider{
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "industrial_grinder", key = "IndustrialGrinderMaxInput", comment = "Industrial Grinder Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "industrial_grinder", key = "IndustrialGrinderMaxEnergy", comment = "Industrial Grinder Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public static final int TANK_CAPACITY = 16_000;
|
||||
public Tank tank;
|
||||
public MultiblockChecker multiblockChecker;
|
||||
int ticksSinceLastChange;
|
||||
|
||||
public IndustrialGrinderBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_GRINDER, "IndustrialGrinder", maxInput, maxEnergy, TRContent.Machine.INDUSTRIAL_GRINDER.block, 7);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] {2, 3, 4, 5};
|
||||
this.inventory = new RebornInventory<>(8, "IndustrialGrinderBlockEntity", 64, this, getInventoryAccess());
|
||||
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_GRINDER, this, 1, 4, this.inventory, inputs, outputs);
|
||||
this.tank = new Tank("IndustrialGrinderBlockEntity", IndustrialGrinderBlockEntity.TANK_CAPACITY, this);
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
public boolean getMultiBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0));
|
||||
final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0));
|
||||
final BlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
|
||||
final boolean center = ((centerBlock.getBlock() instanceof FluidBlock
|
||||
|| centerBlock.getBlock() instanceof FluidBlock)
|
||||
&& centerBlock.getMaterial() == Material.WATER);
|
||||
return down && center && blade && up;
|
||||
}
|
||||
|
||||
private static IInventoryAccess<IndustrialGrinderBlockEntity> getInventoryAccess(){
|
||||
return (slotID, stack, face, direction, blockEntity) -> {
|
||||
if(slotID == 1){
|
||||
//TODO check if the item has fluid in it
|
||||
//return stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).isPresent();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).down();
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 1, 6);
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 6, tank.getFluidType());
|
||||
}
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
if (!world.isClient && getMultiBlock()) {
|
||||
super.tick();
|
||||
}
|
||||
|
||||
tank.compareAndUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
tank.read(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Nullable
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
// fluidSlot first to support automation and shift-click
|
||||
return new ContainerBuilder("industrialgrinder").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).fluidSlot(1, 34, 35).slot(0, 84, 43).outputSlot(2, 126, 18).outputSlot(3, 126, 36)
|
||||
.outputSlot(4, 126, 54).outputSlot(5, 126, 72).outputSlot(6, 34, 55).energySlot(7, 8, 72)
|
||||
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "industrial_sawmill", key = "IndustrialSawmillMaxInput", comment = "Industrial Sawmill Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "industrial_sawmill", key = "IndustrialSawmillMaxEnergy", comment = "Industrial Sawmill Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public static final int TANK_CAPACITY = 16_000;
|
||||
public Tank tank;
|
||||
public MultiblockChecker multiblockChecker;
|
||||
int ticksSinceLastChange;
|
||||
|
||||
public IndustrialSawmillBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_SAWMILL, "IndustrialSawmill", maxInput, maxEnergy, TRContent.Machine.INDUSTRIAL_SAWMILL.block, 6);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3, 4 };
|
||||
this.inventory = new RebornInventory<>(7, "SawmillBlockEntity", 64, this, getInventoryAccess());
|
||||
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_SAWMILL, this, 1, 3, this.inventory, inputs, outputs);
|
||||
this.tank = new Tank("SawmillBlockEntity", IndustrialSawmillBlockEntity.TANK_CAPACITY, this);
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
public boolean getMutliBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.STANDARD_CASING, new BlockPos(0, 2, 0));
|
||||
final boolean blade = multiblockChecker.checkRingY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, 1, 0));
|
||||
final BlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
|
||||
final boolean center = ((centerBlock.getBlock() instanceof FluidBlock
|
||||
|| centerBlock.getBlock() instanceof FluidBlock)
|
||||
&& centerBlock.getMaterial() == Material.WATER);
|
||||
return down && center && blade && up;
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (multiblockChecker == null) {
|
||||
final BlockPos downCenter = pos.offset(getFacing().getOpposite(), 2).down();
|
||||
multiblockChecker = new MultiblockChecker(world, downCenter);
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 1, 5);
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 5, tank.getFluidType());
|
||||
}
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
if (!world.isClient && getMutliBlock()) {
|
||||
super.tick();
|
||||
}
|
||||
|
||||
tank.compareAndUpdate();
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
tank.read(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Nullable
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
|
||||
private static IInventoryAccess<IndustrialSawmillBlockEntity> getInventoryAccess(){
|
||||
return (slotID, stack, face, direction, blockEntity) -> {
|
||||
if(direction == IInventoryAccess.AccessDirection.INSERT){
|
||||
//TODO return if the stack can take fluids
|
||||
//return stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).isPresent();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("industrialsawmill").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).fluidSlot(1, 34, 35).slot(0, 84, 43).outputSlot(2, 126, 25).outputSlot(3, 126, 43)
|
||||
.outputSlot(4, 126, 61).outputSlot(5, 34, 55).energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue()
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
public class MultiblockChecker {
|
||||
|
||||
public static final BlockPos ZERO_OFFSET = BlockPos.ORIGIN;
|
||||
|
||||
public static final String STANDARD_CASING = "standard";
|
||||
public static final String REINFORCED_CASING = "reinforced";
|
||||
public static final String ADVANCED_CASING = "advanced";
|
||||
public static final String CASING_ANY = "any";
|
||||
|
||||
private final World world;
|
||||
private final BlockPos downCenter;
|
||||
|
||||
public MultiblockChecker(World world, BlockPos downCenter) {
|
||||
this.world = world;
|
||||
this.downCenter = downCenter;
|
||||
}
|
||||
|
||||
// TODO: make thid not so ugly
|
||||
public boolean checkCasing(int offX, int offY, int offZ, String type) {
|
||||
Block block = getBlock(offX, offY, offZ).getBlock();
|
||||
if (block == TRContent.MachineBlocks.BASIC.getCasing()|| block == TRContent.MachineBlocks.ADVANCED.getCasing() || block == TRContent.MachineBlocks.INDUSTRIAL.getCasing() ) {
|
||||
if (type == MultiblockChecker.CASING_ANY) {
|
||||
return true;
|
||||
} else if ( type == "standard" && block == TRContent.MachineBlocks.BASIC.getCasing()) {
|
||||
return true;
|
||||
}
|
||||
else if (type == "reinforced" && block == TRContent.MachineBlocks.ADVANCED.getCasing()) {
|
||||
return true;
|
||||
}
|
||||
else if (type == "advanced" && block == TRContent.MachineBlocks.INDUSTRIAL.getCasing()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkAir(int offX, int offY, int offZ) {
|
||||
BlockPos pos = downCenter.add(offX, offY, offZ);
|
||||
return world.isAir(pos);
|
||||
}
|
||||
|
||||
public BlockState getBlock(int offX, int offY, int offZ) {
|
||||
BlockPos pos = downCenter.add(offX, offY, offZ);
|
||||
return world.getBlockState(pos);
|
||||
}
|
||||
|
||||
public boolean checkRectY(int sizeX, int sizeZ, String casingType, BlockPos offset) {
|
||||
for (int x = -sizeX; x <= sizeX; x++) {
|
||||
for (int z = -sizeZ; z <= sizeZ; z++) {
|
||||
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkRectZ(int sizeX, int sizeY, String casingType, BlockPos offset) {
|
||||
for (int x = -sizeX; x <= sizeX; x++) {
|
||||
for (int y = -sizeY; y <= sizeY; y++) {
|
||||
if (!checkCasing(x + offset.getX(), y + offset.getY(), offset.getZ(), casingType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkRectX(int sizeZ, int sizeY, String casingType, BlockPos offset) {
|
||||
for (int z = -sizeZ; z <= sizeZ; z++) {
|
||||
for (int y = -sizeY; y <= sizeY; y++) {
|
||||
if (!checkCasing(offset.getX(), y + offset.getY(), z + offset.getZ(), casingType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkRingY(int sizeX, int sizeZ, String casingType, BlockPos offset) {
|
||||
for (int x = -sizeX; x <= sizeX; x++) {
|
||||
for (int z = -sizeZ; z <= sizeZ; z++) {
|
||||
if ((x == sizeX || x == -sizeX) || (z == sizeZ || z == -sizeZ)) {
|
||||
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkRingYHollow(int sizeX, int sizeZ, String casingType, BlockPos offset) {
|
||||
for (int x = -sizeX; x <= sizeX; x++) {
|
||||
for (int z = -sizeZ; z <= sizeZ; z++) {
|
||||
if ((x == sizeX || x == -sizeX) || (z == sizeZ || z == -sizeZ)) {
|
||||
if (!checkCasing(x + offset.getX(), offset.getY(), z + offset.getZ(), casingType))
|
||||
return false;
|
||||
} else if (!checkAir(x + offset.getX(), offset.getY(), z + offset.getZ()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.multiblock;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class VacuumFreezerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "vacuumfreezer", key = "VacuumFreezerInput", comment = "Vacuum Freezer Max Input (Value in EU)")
|
||||
public static int maxInput = 64;
|
||||
@ConfigRegistry(config = "machines", category = "vacuumfreezer", key = "VacuumFreezerMaxEnergy", comment = "Vacuum Freezer Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 64_000;
|
||||
|
||||
public MultiblockChecker multiblockChecker;
|
||||
|
||||
public VacuumFreezerBlockEntity() {
|
||||
super(TRBlockEntities.VACUUM_FREEZER, "VacuumFreezer", maxInput, maxEnergy, TRContent.Machine.VACUUM_FREEZER.block, 2);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
final int[] outputs = new int[] { 1 };
|
||||
this.inventory = new RebornInventory<>(3, "VacuumFreezerBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.VACUUM_FREEZER, this, 2, 1, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
public boolean getMultiBlock() {
|
||||
if (multiblockChecker == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean up = multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, MultiblockChecker.ZERO_OFFSET);
|
||||
final boolean down = multiblockChecker.checkRectY(1, 1, MultiblockChecker.REINFORCED_CASING, new BlockPos(0, -2, 0));
|
||||
final boolean chamber = multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.ADVANCED_CASING, new BlockPos(0, -1, 0));
|
||||
return down && chamber && up;
|
||||
}
|
||||
|
||||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!world.isClient && getMultiBlock()) {
|
||||
super.tick();
|
||||
}
|
||||
}
|
||||
|
||||
// BlockEntity
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
multiblockChecker = new MultiblockChecker(world, pos.down());
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("vacuumfreezer").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue()
|
||||
.syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class AlloySmelterBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "alloy_smelter", key = "AlloySmelterMaxInput", comment = "Alloy Smelter Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "alloy_smelter", key = "AlloySmelterMaxEnergy", comment = "Alloy Smelter Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1_000;
|
||||
|
||||
public AlloySmelterBlockEntity() {
|
||||
super(TRBlockEntities.ALLOY_SMELTER, "AlloySmelter", maxInput, maxEnergy, TRContent.Machine.ALLOY_SMELTER.block, 3);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2 };
|
||||
this.inventory = new RebornInventory<>(4, "AlloySmelterBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.ALLOY_SMELTER, this, 2, 1, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("alloysmelter").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this)
|
||||
.filterSlot(0, 34, 47,
|
||||
stack -> ModRecipes.ALLOY_SMELTER.getRecipes(player.world).stream().anyMatch(recipe -> recipe.getRebornIngredients().get(0).test(stack)))
|
||||
.filterSlot(1, 126, 47,
|
||||
stack -> ModRecipes.ALLOY_SMELTER.getRecipes(player.world).stream().anyMatch(recipe -> recipe.getRebornIngredients().get(1).test(stack)))
|
||||
.outputSlot(2, 80, 47).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory()
|
||||
.create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class AssemblingMachineBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "assembling_machine", key = "AssemblingMachineMaxInput", comment = "Assembling Machine Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "assembling_machine", key = "AssemblingMachineMaxEnergy", comment = "Assembling Machine Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public AssemblingMachineBlockEntity() {
|
||||
super(TRBlockEntities.ASSEMBLY_MACHINE, "AssemblingMachine", maxInput, maxEnergy, TRContent.Machine.ASSEMBLY_MACHINE.block, 3);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2 };
|
||||
this.inventory = new RebornInventory<>(4, "AssemblingMachineBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.ASSEMBLING_MACHINE, this, 2, 2, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("assemblingmachine").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 55, 35).slot(1, 55, 55).outputSlot(2, 101, 45).energySlot(3, 8, 72)
|
||||
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,457 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.container.Container;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.IInventoryAccess;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.events.TRRecipeHandler;
|
||||
import techreborn.init.ModSounds;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 20/06/2017.
|
||||
*/
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "autocrafter", key = "AutoCrafterInput", comment = "AutoCrafting Table Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "autocrafter", key = "AutoCrafterMaxEnergy", comment = "AutoCrafting Table Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public RebornInventory<AutoCraftingTableBlockEntity> inventory = new RebornInventory<>(11, "AutoCraftingTableBlockEntity", 64, this, getInventoryAccess());
|
||||
public int progress;
|
||||
public int maxProgress = 120;
|
||||
public int euTick = 10;
|
||||
|
||||
CraftingInventory inventoryCrafting = null;
|
||||
Recipe lastCustomRecipe = null;
|
||||
Recipe lastRecipe = null;
|
||||
|
||||
public boolean locked = true;
|
||||
|
||||
public AutoCraftingTableBlockEntity() {
|
||||
super(TRBlockEntities.AUTO_CRAFTING_TABLE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Recipe getIRecipe() {
|
||||
CraftingInventory crafting = getCraftingInventory();
|
||||
if (!crafting.isInvEmpty()) {
|
||||
if (lastRecipe != null) {
|
||||
if (lastRecipe.matches(crafting, world)) {
|
||||
return lastRecipe;
|
||||
}
|
||||
}
|
||||
for (Recipe testRecipe : TRRecipeHandler.getRecipes(world, RecipeType.CRAFTING)) {
|
||||
if (testRecipe.matches(crafting, world)) {
|
||||
lastRecipe = testRecipe;
|
||||
return testRecipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CraftingInventory getCraftingInventory() {
|
||||
if (inventoryCrafting == null) {
|
||||
inventoryCrafting = new CraftingInventory(new Container(null, -1) {
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity playerIn) {
|
||||
return false;
|
||||
}
|
||||
}, 3, 3);
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inventoryCrafting.setInvStack(i, inventory.getInvStack(i));
|
||||
}
|
||||
return inventoryCrafting;
|
||||
}
|
||||
|
||||
public boolean canMake(Recipe recipe) {
|
||||
if (recipe != null && recipe.fits(3, 3)) {
|
||||
boolean missingOutput = false;
|
||||
int[] stacksInSlots = new int[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
stacksInSlots[i] = inventory.getInvStack(i).getCount();
|
||||
}
|
||||
|
||||
DefaultedList<Ingredient> ingredients = recipe.getPreviewInputs();
|
||||
for (Ingredient ingredient : ingredients) {
|
||||
if (ingredient != Ingredient.EMPTY) {
|
||||
boolean foundIngredient = false;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack stack = inventory.getInvStack(i);
|
||||
int requiredSize = locked ? 1 : 0;
|
||||
if (stack.getMaxCount() == 1) {
|
||||
requiredSize = 0;
|
||||
}
|
||||
if (stacksInSlots[i] > requiredSize) {
|
||||
if (ingredient.method_8093(stack)) {
|
||||
if (stack.getItem().getRecipeRemainder() != null) {
|
||||
if (!hasRoomForExtraItem(new ItemStack(stack.getItem().getRecipeRemainder()))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
foundIngredient = true;
|
||||
stacksInSlots[i]--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundIngredient) {
|
||||
missingOutput = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!missingOutput) {
|
||||
if (hasOutputSpace(recipe.getOutput(), 9)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean hasRoomForExtraItem(ItemStack stack) {
|
||||
ItemStack extraOutputSlot = inventory.getInvStack(10);
|
||||
if (extraOutputSlot.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return hasOutputSpace(stack, 10);
|
||||
}
|
||||
|
||||
public boolean hasOutputSpace(ItemStack output, int slot) {
|
||||
ItemStack stack = inventory.getInvStack(slot);
|
||||
if (stack.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (ItemUtils.isItemEqual(stack, output, true, true)) {
|
||||
if (stack.getMaxCount() > stack.getCount() + output.getCount()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean make(Recipe recipe) {
|
||||
if (recipe == null || !canMake(recipe)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < recipe.getPreviewInputs().size(); i++) {
|
||||
DefaultedList<Ingredient> ingredients = recipe.getPreviewInputs();
|
||||
Ingredient ingredient = ingredients.get(i);
|
||||
// Looks for the best slot to take it from
|
||||
ItemStack bestSlot = inventory.getInvStack(i);
|
||||
if (ingredient.method_8093(bestSlot)) {
|
||||
handleContainerItem(bestSlot);
|
||||
bestSlot.decrement(1);
|
||||
} else {
|
||||
for (int j = 0; j < 9; j++) {
|
||||
ItemStack stack = inventory.getInvStack(j);
|
||||
if (ingredient.method_8093(stack)) {
|
||||
handleContainerItem(stack);
|
||||
stack.decrement(1); // TODO is this right? or do I need
|
||||
// to use it as an actull
|
||||
// crafting grid
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStack output = inventory.getInvStack(9);
|
||||
// TODO fire forge recipe event
|
||||
ItemStack ouputStack = recipe.craft(getCraftingInventory());
|
||||
if (output.isEmpty()) {
|
||||
inventory.setInvStack(9, ouputStack.copy());
|
||||
} else {
|
||||
// TODO use ouputStack in someway?
|
||||
output.increment(recipe.getOutput().getCount());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleContainerItem(ItemStack stack) {
|
||||
if (stack.getItem().hasRecipeRemainder()) {
|
||||
ItemStack containerItem = new ItemStack(stack.getItem().getRecipeRemainder());
|
||||
ItemStack extraOutputSlot = inventory.getInvStack(10);
|
||||
if (hasOutputSpace(containerItem, 10)) {
|
||||
if (extraOutputSlot.isEmpty()) {
|
||||
inventory.setInvStack(10, containerItem.copy());
|
||||
} else if (ItemUtils.isItemEqual(extraOutputSlot, containerItem, true, true)
|
||||
&& extraOutputSlot.getMaxCount() < extraOutputSlot.getCount() + containerItem.getCount()) {
|
||||
extraOutputSlot.increment(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasIngredient(Ingredient ingredient) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack stack = inventory.getInvStack(i);
|
||||
if (ingredient.method_8093(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isItemValidForRecipeSlot(Recipe recipe, ItemStack stack, int slotID) {
|
||||
if (recipe == null) {
|
||||
return true;
|
||||
}
|
||||
int bestSlot = findBestSlotForStack(recipe, stack);
|
||||
if (bestSlot != -1) {
|
||||
return bestSlot == slotID;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int findBestSlotForStack(Recipe recipe, ItemStack stack) {
|
||||
if (recipe == null) {
|
||||
return -1;
|
||||
}
|
||||
DefaultedList<Ingredient> ingredients = recipe.getPreviewInputs();
|
||||
List<Integer> possibleSlots = new ArrayList<>();
|
||||
for (int i = 0; i < recipe.getPreviewInputs().size(); i++) {
|
||||
ItemStack stackInSlot = inventory.getInvStack(i);
|
||||
Ingredient ingredient = ingredients.get(i);
|
||||
if (ingredient != Ingredient.EMPTY && ingredient.method_8093(stack)) {
|
||||
if (stackInSlot.isEmpty()) {
|
||||
possibleSlots.add(i);
|
||||
} else if (stackInSlot.getItem() == stack.getItem()) {
|
||||
if (stackInSlot.getMaxCount() >= stackInSlot.getCount() + stack.getCount()) {
|
||||
possibleSlots.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Slot, count
|
||||
Pair<Integer, Integer> smallestCount = null;
|
||||
for (Integer slot : possibleSlots) {
|
||||
ItemStack slotStack = inventory.getInvStack(slot);
|
||||
if (slotStack.isEmpty()) {
|
||||
return slot;
|
||||
}
|
||||
if (smallestCount == null) {
|
||||
smallestCount = Pair.of(slot, slotStack.getCount());
|
||||
} else if (smallestCount.getRight() >= slotStack.getCount()) {
|
||||
smallestCount = Pair.of(slot, slotStack.getCount());
|
||||
}
|
||||
}
|
||||
if (smallestCount != null) {
|
||||
return smallestCount.getLeft();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public int getMaxProgress() {
|
||||
if (maxProgress == 0) {
|
||||
maxProgress = 1;
|
||||
}
|
||||
return maxProgress;
|
||||
}
|
||||
|
||||
public void setMaxProgress(int maxProgress) {
|
||||
this.maxProgress = maxProgress;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
Recipe recipe = getIRecipe();
|
||||
if (recipe != null) {
|
||||
if (progress >= maxProgress) {
|
||||
if (make(recipe)) {
|
||||
progress = 0;
|
||||
}
|
||||
} else {
|
||||
if (canMake(recipe)) {
|
||||
if (canUseEnergy(euTick)) {
|
||||
progress++;
|
||||
if (progress == 1) {
|
||||
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.AUTO_CRAFTING,
|
||||
SoundCategory.BLOCKS, 0.3F, 0.8F);
|
||||
}
|
||||
useEnergy(euTick);
|
||||
}
|
||||
} else {
|
||||
progress = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recipe == null) {
|
||||
progress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Easyest way to sync back to the client
|
||||
public int getLockedInt() {
|
||||
return locked ? 1 : 0;
|
||||
}
|
||||
|
||||
public void setLockedInt(int lockedInt) {
|
||||
locked = lockedInt == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction enumFacing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction enumFacing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
tag.putBoolean("locked", locked);
|
||||
return super.toTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tag) {
|
||||
if (tag.containsKey("locked")) {
|
||||
locked = tag.getBoolean("locked");
|
||||
}
|
||||
super.fromTag(tag);
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static IInventoryAccess<AutoCraftingTableBlockEntity> getInventoryAccess(){
|
||||
return (slotID, stack, facing, direction, blockEntity) -> {
|
||||
switch (direction){
|
||||
case INSERT:
|
||||
if (slotID > 8) {
|
||||
return false;
|
||||
}
|
||||
int bestSlot = blockEntity.findBestSlotForStack(blockEntity.getIRecipe(), stack);
|
||||
if (bestSlot != -1) {
|
||||
return slotID == bestSlot;
|
||||
}
|
||||
return true;
|
||||
case EXTRACT:
|
||||
return slotID > 8;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// This machine doesnt have a facing
|
||||
@Override
|
||||
public Direction getFacingEnum() {
|
||||
return Direction.NORTH;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return TRContent.Machine.AUTO_CRAFTING_TABLE.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
|
||||
return new ContainerBuilder("autocraftingtable").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 28, 25).slot(1, 46, 25).slot(2, 64, 25).slot(3, 28, 43).slot(4, 46, 43)
|
||||
.slot(5, 64, 43).slot(6, 28, 61).slot(7, 46, 61).slot(8, 64, 61).outputSlot(9, 145, 42)
|
||||
.outputSlot(10, 145, 70).syncEnergyValue().syncIntegerValue(this::getProgress, this::setProgress)
|
||||
.syncIntegerValue(this::getMaxProgress, this::setMaxProgress)
|
||||
.syncIntegerValue(this::getLockedInt, this::setLockedInt).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlotConfig() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ChemicalReactorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "chemical_reactor", key = "ChemicalReactorMaxInput", comment = "Chemical Reactor Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "chemical_reactor", key = "ChemicalReactorMaxEnergy", comment = "Chemical Reactor Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public ChemicalReactorBlockEntity() {
|
||||
super(TRBlockEntities.CHEMICAL_REACTOR, "ChemicalReactor", maxInput, maxEnergy, TRContent.Machine.CHEMICAL_REACTOR.block, 3);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2 };
|
||||
this.inventory = new RebornInventory<>(4, "ChemicalReactorBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.CHEMICAL_REACTOR, this, 2, 2, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("chemicalreactor").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).energySlot(3, 8, 72)
|
||||
.syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class CompressorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "compressor", key = "CompressorInput", comment = "Compressor Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "compressor", key = "CompressorMaxEnergy", comment = "Compressor Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000;
|
||||
|
||||
public CompressorBlockEntity() {
|
||||
super(TRBlockEntities.COMPRESSOR, "Compressor", maxInput, maxEnergy, TRContent.Machine.COMPRESSOR.block, 2);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
final int[] outputs = new int[] { 1 };
|
||||
this.inventory = new RebornInventory<>(3, "CompressorBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.COMPRESSOR, this, 2, 1, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("compressor").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue()
|
||||
.syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.events.TRRecipeHandler;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "electric_furnace", key = "ElectricFurnaceInput", comment = "Electric Furnace Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "electric_furnace", key = "ElectricFurnaceMaxEnergy", comment = "Electric Furnace Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000;
|
||||
|
||||
public RebornInventory<ElectricFurnaceBlockEntity> inventory = new RebornInventory<>(3, "ElectricFurnaceBlockEntity", 64, this).withConfiguredAccess();
|
||||
public int progress;
|
||||
public int fuelScale = 100;
|
||||
public int cost = 6;
|
||||
int input1 = 0;
|
||||
int output = 1;
|
||||
boolean wasBurning = false;
|
||||
|
||||
public ElectricFurnaceBlockEntity() {
|
||||
super(TRBlockEntities.ELECTRIC_FURNACE );
|
||||
}
|
||||
|
||||
public int gaugeProgressScaled(int scale) {
|
||||
return progress * scale / (int) (fuelScale * (1.0 - getSpeedMultiplier()));
|
||||
}
|
||||
|
||||
public void cookItems() {
|
||||
if (canSmelt()) {
|
||||
final ItemStack itemstack = TRRecipeHandler.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(input1));
|
||||
|
||||
if (inventory.getInvStack(output).isEmpty()) {
|
||||
inventory.setInvStack(output, itemstack.copy());
|
||||
} else if (inventory.getInvStack(output).isItemEqualIgnoreDamage(itemstack)) {
|
||||
inventory.getInvStack(output).increment(itemstack.getCount());
|
||||
}
|
||||
if (inventory.getInvStack(input1).getCount() > 1) {
|
||||
inventory.shrinkSlot(input1, 1);
|
||||
} else {
|
||||
inventory.setInvStack(input1, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canSmelt() {
|
||||
if (inventory.getInvStack(input1).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final ItemStack itemstack = TRRecipeHandler.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(input1));
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (inventory.getInvStack(output).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (!inventory.getInvStack(output).isItemEqualIgnoreDamage(itemstack)) {
|
||||
return false;
|
||||
}
|
||||
final int result = inventory.getInvStack(output).getCount() + itemstack.getCount();
|
||||
return result <= this.inventory.getStackLimit() && result <= itemstack.getMaxCount();
|
||||
}
|
||||
|
||||
public boolean isBurning() {
|
||||
return getEnergy() > getEuPerTick(cost);
|
||||
}
|
||||
|
||||
public ItemStack getResultFor(ItemStack stack) {
|
||||
final ItemStack result = TRRecipeHandler.getMatchingRecipes(world, RecipeType.SMELTING, stack);
|
||||
if (!result.isEmpty()) {
|
||||
return result.copy();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
if (wasBurning != (progress > 0)) {
|
||||
// skips updating the block state for 1 tick, to prevent the machine from
|
||||
// turning on/off rapidly causing fps drops
|
||||
if (wasBurning && progress == 0 && canSmelt()) {
|
||||
wasBurning = true;
|
||||
return;
|
||||
}
|
||||
final BlockState BlockStateContainer = world.getBlockState(pos);
|
||||
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
|
||||
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
|
||||
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != progress > 0)
|
||||
blockMachineBase.setActive(progress > 0, world, pos);
|
||||
}
|
||||
wasBurning = (progress > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setBurnTime(final int burnTime) {
|
||||
this.progress = burnTime;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.tick();
|
||||
charge(2);
|
||||
|
||||
final boolean burning = isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (isBurning() && canSmelt()) {
|
||||
updateState();
|
||||
if (canUseEnergy(getEuPerTick(cost))) {
|
||||
useEnergy(getEuPerTick(cost));
|
||||
progress++;
|
||||
if (progress >= Math.max((int) (fuelScale * (1.0 - getSpeedMultiplier())), 5)) {
|
||||
progress = 0;
|
||||
cookItems();
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updateState();
|
||||
}
|
||||
if (burning != isBurning()) {
|
||||
updateInventory = true;
|
||||
}
|
||||
if (updateInventory) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.ELECTRIC_FURNACE.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<ElectricFurnaceBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("electricfurnace").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue()
|
||||
.syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ExtractorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "extractor", key = "ExtractorInput", comment = "Extractor Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1_000;
|
||||
|
||||
public ExtractorBlockEntity() {
|
||||
super(TRBlockEntities.EXTRACTOR, "Extractor", maxInput, maxEnergy, TRContent.Machine.EXTRACTOR.block, 2);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
final int[] outputs = new int[] { 1 };
|
||||
this.inventory = new RebornInventory<>(3, "ExtractorBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.EXTRACTOR, this, 2, 1, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("extractor").player(player.inventory).inventory().hotbar().addInventory().blockEntity(this)
|
||||
.slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue().syncCrafterValue()
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class GrinderBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "grinder", key = "GrinderInput", comment = "Grinder Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "grinder", key = "GrinderMaxEnergy", comment = "Grinder Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1_000;
|
||||
|
||||
public GrinderBlockEntity() {
|
||||
super(TRBlockEntities.GRINDER, "Grinder", maxInput, maxEnergy, TRContent.Machine.GRINDER.block, 2);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
final int[] outputs = new int[] { 1 };
|
||||
this.inventory = new RebornInventory<>(3, "GrinderBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.GRINDER, this, 2, 1, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("grinder").player(player.inventory).inventory().hotbar().addInventory().blockEntity(this)
|
||||
.slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue().syncCrafterValue()
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.items.DynamicCell;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class IndustrialElectrolyzerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "industrial_electrolyzer", key = "IndustrialElectrolyzerMaxInput", comment = "Industrial Electrolyzer Max Input (Value in EU)")
|
||||
public static int maxInput = 128;
|
||||
@ConfigRegistry(config = "machines", category = "industrial_electrolyzer", key = "IndustrialElectrolyzerMaxEnergy", comment = "Industrial Electrolyzer Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
|
||||
public IndustrialElectrolyzerBlockEntity() {
|
||||
super(TRBlockEntities.INDUSTRIAL_ELECTROLYZER, "IndustrialElectrolyzer", maxInput, maxEnergy, TRContent.Machine.INDUSTRIAL_ELECTROLYZER.block, 6);
|
||||
final int[] inputs = new int[] { 0, 1 };
|
||||
final int[] outputs = new int[] { 2, 3, 4, 5 };
|
||||
this.inventory = new RebornInventory<>(7, "IndustrialElectrolyzerBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new RecipeCrafter(ModRecipes.INDUSTRIAL_ELECTROLYZER, this, 2, 4, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("industrialelectrolyzer").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this)
|
||||
.filterSlot(1, 47, 72, stack -> ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true))
|
||||
.filterSlot(0, 81, 72, stack -> !ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true))
|
||||
.outputSlot(2, 51, 24).outputSlot(3, 71, 24).outputSlot(4, 91, 24).outputSlot(5, 111, 24)
|
||||
.energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.blocks.tier1.BlockPlayerDetector;
|
||||
import techreborn.blocks.tier1.BlockPlayerDetector.PlayerDetectorType;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "player_detector", key = "PlayerDetectorMaxInput", comment = "Player Detector Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "player_detector", key = "PlayerDetectorMaxEnergy", comment = "Player Detector Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10000;
|
||||
@ConfigRegistry(config = "machines", category = "player_detector", key = "PlayerDetectorEUPerSecond", comment = "Player Detector Energy Consumption per second (Value in EU)")
|
||||
public static int euPerTick = 10;
|
||||
|
||||
public String owenerUdid = "";
|
||||
boolean redstone = false;
|
||||
|
||||
public PlayerDectectorBlockEntity() {
|
||||
super(TRBlockEntities.PLAYER_DETECTOR);
|
||||
}
|
||||
|
||||
public boolean isProvidingPower() {
|
||||
return redstone;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient && world.getTime() % 20 == 0) {
|
||||
boolean lastRedstone = redstone;
|
||||
redstone = false;
|
||||
if (canUseEnergy(euPerTick)) {
|
||||
for(PlayerEntity player : world.getPlayers()){
|
||||
if (player.distanceTo(player) <= 256.0D) {
|
||||
PlayerDetectorType type = world.getBlockState(pos).get(BlockPlayerDetector.TYPE);
|
||||
if (type == PlayerDetectorType.ALL) {// ALL
|
||||
redstone = true;
|
||||
} else if (type == PlayerDetectorType.OTHERS) {// Others
|
||||
if (!owenerUdid.isEmpty() && !owenerUdid.equals(player.getUuid().toString())) {
|
||||
redstone = true;
|
||||
}
|
||||
} else {// You
|
||||
if (!owenerUdid.isEmpty() && owenerUdid.equals(player.getUuid().toString())) {
|
||||
redstone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
useEnergy(euPerTick);
|
||||
}
|
||||
if (lastRedstone != redstone) {
|
||||
WorldUtils.updateBlock(world, pos);
|
||||
world.updateNeighborsAlways(pos, world.getBlockState(pos).getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tag) {
|
||||
super.fromTag(tag);
|
||||
owenerUdid = tag.getString("ownerID");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
tag.putString("ownerID", owenerUdid);
|
||||
return tag;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity p0) {
|
||||
return TRContent.Machine.PLAYER_DETECTOR.getStack();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.IUpgrade;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "recycler", key = "RecyclerInput", comment = "Recycler Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "recycler", key = "RecyclerMaxEnergy", comment = "Recycler Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1000;
|
||||
@ConfigRegistry(config = "machines", category = "recycler", key = "produceIC2Scrap", comment = "When enabled and when ic2 is installed the recycler will make ic2 scrap")
|
||||
public static boolean produceIC2Scrap = false;
|
||||
|
||||
private final RebornInventory<RecyclerBlockEntity> inventory = new RebornInventory<>(3, "RecyclerBlockEntity", 64, this).withConfiguredAccess();
|
||||
private final int cost = 2;
|
||||
private final int time = 15;
|
||||
private final int chance = 6;
|
||||
private boolean isBurning;
|
||||
private int progress;
|
||||
|
||||
public RecyclerBlockEntity() {
|
||||
super(TRBlockEntities.RECYCLER);
|
||||
}
|
||||
|
||||
public int gaugeProgressScaled(int scale) {
|
||||
return progress * scale / time;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public void recycleItems() {
|
||||
ItemStack itemstack = TRContent.Parts.SCRAP.getStack();
|
||||
final int randomchance = this.world.random.nextInt(chance);
|
||||
|
||||
if (randomchance == 1) {
|
||||
if (inventory.getInvStack(1).isEmpty()) {
|
||||
inventory.setInvStack(1, itemstack.copy());
|
||||
}
|
||||
else {
|
||||
inventory.getInvStack(1).increment(itemstack.getCount());
|
||||
}
|
||||
}
|
||||
inventory.shrinkSlot(0, 1);
|
||||
}
|
||||
|
||||
public boolean canRecycle() {
|
||||
return !inventory.getInvStack(0) .isEmpty() && hasSlotGotSpace(1);
|
||||
}
|
||||
|
||||
public boolean hasSlotGotSpace(int slot) {
|
||||
if (inventory.getInvStack(slot).isEmpty()) {
|
||||
return true;
|
||||
} else if (inventory.getInvStack(slot).getCount() < inventory.getInvStack(slot).getMaxCount()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBurning() {
|
||||
return isBurning;
|
||||
}
|
||||
|
||||
public void setBurning(boolean burning) {
|
||||
this.isBurning = burning;
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
final BlockState BlockStateContainer = world.getBlockState(pos);
|
||||
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
|
||||
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
|
||||
boolean shouldBurn = isBurning || (canRecycle() && canUseEnergy(getEuPerTick(cost)));
|
||||
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != shouldBurn) {
|
||||
blockMachineBase.setActive(isBurning, world, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
charge(2);
|
||||
|
||||
boolean updateInventory = false;
|
||||
if (canRecycle() && !isBurning() && getEnergy() != 0) {
|
||||
setBurning(true);
|
||||
}
|
||||
else if (isBurning()) {
|
||||
if (useEnergy(getEuPerTick(cost)) != getEuPerTick(cost)) {
|
||||
this.setBurning(false);
|
||||
}
|
||||
progress++;
|
||||
if (progress >= Math.max((int) (time* (1.0 - getSpeedMultiplier())), 1)) {
|
||||
progress = 0;
|
||||
recycleItems();
|
||||
updateInventory = true;
|
||||
setBurning(false);
|
||||
}
|
||||
}
|
||||
|
||||
updateState();
|
||||
|
||||
if (updateInventory) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.RECYCLER.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<RecyclerBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
|
||||
return new ContainerBuilder("recycler").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 55, 45, itemStack -> itemStack.getItem() instanceof IUpgrade).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue()
|
||||
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,424 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.container.Container;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.RollingMachineRecipe;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
//TODO add tick and power bars.
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "rolling_machine", key = "RollingMachineMaxInput", comment = "Rolling Machine Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "rolling_machine", key = "RollingMachineEnergyPerTick", comment = "Rolling Machine Energy Per Tick (Value in EU)")
|
||||
public static int energyPerTick = 5;
|
||||
@ConfigRegistry(config = "machines", category = "rolling_machine", key = "RollingMachineEnergyRunTime", comment = "Rolling Machine Run Time")
|
||||
public static int runTime = 250;
|
||||
@ConfigRegistry(config = "machines", category = "rolling_machine", key = "RollingMachineMaxEnergy", comment = "Rolling Machine Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10000;
|
||||
|
||||
public int[] craftingSlots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
private CraftingInventory craftCache;
|
||||
public RebornInventory<RollingMachineBlockEntity> inventory = new RebornInventory<>(12, "RollingMachineBlockEntity", 64, this).withConfiguredAccess();
|
||||
public boolean isRunning;
|
||||
public int tickTime;
|
||||
@Nonnull
|
||||
public ItemStack currentRecipeOutput;
|
||||
public Recipe currentRecipe;
|
||||
private int outputSlot;
|
||||
public boolean locked = false;
|
||||
public int balanceSlot = 0;
|
||||
|
||||
public RollingMachineBlockEntity() {
|
||||
super(TRBlockEntities.ROLLING_MACHINE);
|
||||
outputSlot = 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
charge(10);
|
||||
|
||||
CraftingInventory craftMatrix = getCraftingMatrix();
|
||||
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
|
||||
if (currentRecipe != null) {
|
||||
setIsActive(true);
|
||||
if (world.getTime() % 2 == 0) {
|
||||
Optional<CraftingInventory> balanceResult = balanceRecipe(craftMatrix);
|
||||
if (balanceResult.isPresent()) {
|
||||
craftMatrix = balanceResult.get();
|
||||
}
|
||||
}
|
||||
currentRecipeOutput = currentRecipe.craft(craftMatrix);
|
||||
} else {
|
||||
currentRecipeOutput = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (!currentRecipeOutput.isEmpty() && canMake(craftMatrix)) {
|
||||
if (tickTime >= Math.max((int) (runTime * (1.0 - getSpeedMultiplier())), 1)) {
|
||||
currentRecipeOutput = RollingMachineRecipe.instance.findMatchingRecipeOutput(craftMatrix, world);
|
||||
if (!currentRecipeOutput.isEmpty()) {
|
||||
boolean hasCrafted = false;
|
||||
if (inventory.getInvStack(outputSlot).isEmpty()) {
|
||||
inventory.setInvStack(outputSlot, currentRecipeOutput);
|
||||
tickTime = 0;
|
||||
hasCrafted = true;
|
||||
} else {
|
||||
if (inventory.getInvStack(outputSlot).getCount()
|
||||
+ currentRecipeOutput.getCount() <= currentRecipeOutput.getMaxCount()) {
|
||||
final ItemStack stack = inventory.getInvStack(outputSlot);
|
||||
stack.setCount(stack.getCount() + currentRecipeOutput.getCount());
|
||||
inventory.setInvStack(outputSlot, stack);
|
||||
tickTime = 0;
|
||||
hasCrafted = true;
|
||||
} else {
|
||||
setIsActive(false);
|
||||
}
|
||||
}
|
||||
if (hasCrafted) {
|
||||
for (int i = 0; i < craftMatrix.getInvSize(); i++) {
|
||||
inventory.shrinkSlot(i, 1);
|
||||
}
|
||||
currentRecipeOutput = ItemStack.EMPTY;
|
||||
currentRecipe = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tickTime = 0;
|
||||
}
|
||||
if (!currentRecipeOutput.isEmpty()) {
|
||||
if (canUseEnergy(getEuPerTick(energyPerTick))
|
||||
&& tickTime < Math.max((int) (runTime * (1.0 - getSpeedMultiplier())), 1)
|
||||
&& canMake(craftMatrix)) {
|
||||
useEnergy(getEuPerTick(energyPerTick));
|
||||
tickTime++;
|
||||
} else {
|
||||
setIsActive(false);
|
||||
}
|
||||
}
|
||||
if (currentRecipeOutput.isEmpty()) {
|
||||
tickTime = 0;
|
||||
currentRecipe = null;
|
||||
setIsActive(canMake(getCraftingMatrix()));
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsActive(boolean active) {
|
||||
if (active == isRunning){
|
||||
return;
|
||||
}
|
||||
isRunning = active;
|
||||
if (this.getWorld().getBlockState(this.getPos()).getBlock() instanceof BlockMachineBase) {
|
||||
BlockMachineBase blockMachineBase = (BlockMachineBase)this.getWorld().getBlockState(this.getPos()).getBlock();
|
||||
blockMachineBase.setActive(active, this.getWorld(), this.getPos());
|
||||
}
|
||||
this.getWorld().updateListeners(this.getPos(), this.getWorld().getBlockState(this.getPos()), this.getWorld().getBlockState(this.getPos()), 3);
|
||||
}
|
||||
|
||||
public Optional<CraftingInventory> balanceRecipe(CraftingInventory craftCache) {
|
||||
if (currentRecipe == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (world.isClient) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!locked) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (craftCache.isInvEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
balanceSlot++;
|
||||
if (balanceSlot > craftCache.getInvSize()) {
|
||||
balanceSlot = 0;
|
||||
}
|
||||
//Find the best slot for each item in a recipe, and move it if needed
|
||||
ItemStack sourceStack = inventory.getInvStack(balanceSlot);
|
||||
if (sourceStack.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<Integer> possibleSlots = new ArrayList<>();
|
||||
for (int s = 0; s < currentRecipe.getPreviewInputs().size(); s++) {
|
||||
ItemStack stackInSlot = inventory.getInvStack(s);
|
||||
Ingredient ingredient = (Ingredient) currentRecipe.getPreviewInputs().get(s);
|
||||
if (ingredient != Ingredient.EMPTY && ingredient.method_8093(sourceStack)) {
|
||||
if (stackInSlot.isEmpty()) {
|
||||
possibleSlots.add(s);
|
||||
} else if (stackInSlot.getItem() == sourceStack.getItem()) {
|
||||
possibleSlots.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!possibleSlots.isEmpty()){
|
||||
int totalItems = possibleSlots.stream()
|
||||
.mapToInt(value -> inventory.getInvStack(value).getCount()).sum();
|
||||
int slots = possibleSlots.size();
|
||||
|
||||
//This makes an array of ints with the best possible slot EnvTyperibution
|
||||
int[] split = new int[slots];
|
||||
int remainder = totalItems % slots;
|
||||
Arrays.fill(split, totalItems / slots);
|
||||
while (remainder > 0){
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if(remainder > 0){
|
||||
split[i] +=1;
|
||||
remainder --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> slotEnvTyperubution = possibleSlots.stream()
|
||||
.mapToInt(value -> inventory.getInvStack(value).getCount())
|
||||
.boxed().collect(Collectors.toList());
|
||||
|
||||
boolean needsBalance = false;
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
int required = split[i];
|
||||
if(slotEnvTyperubution.contains(required)){
|
||||
//We need to remove the int, not at the int, this seems to work around that
|
||||
slotEnvTyperubution.remove(new Integer(required));
|
||||
} else {
|
||||
needsBalance = true;
|
||||
}
|
||||
}
|
||||
if (!needsBalance) {
|
||||
return Optional.empty();
|
||||
}
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
//Slot, count
|
||||
Pair<Integer, Integer> bestSlot = null;
|
||||
for (Integer slot : possibleSlots) {
|
||||
ItemStack slotStack = inventory.getInvStack(slot);
|
||||
if (slotStack.isEmpty()) {
|
||||
bestSlot = Pair.of(slot, 0);
|
||||
}
|
||||
if (bestSlot == null) {
|
||||
bestSlot = Pair.of(slot, slotStack.getCount());
|
||||
} else if (bestSlot.getRight() >= slotStack.getCount()) {
|
||||
bestSlot = Pair.of(slot, slotStack.getCount());
|
||||
}
|
||||
}
|
||||
if (bestSlot == null
|
||||
|| bestSlot.getLeft() == balanceSlot
|
||||
|| bestSlot.getRight() == sourceStack.getCount()
|
||||
|| inventory.getInvStack(bestSlot.getLeft()).isEmpty()
|
||||
|| !ItemUtils.isItemEqual(sourceStack, inventory.getInvStack(bestSlot.getLeft()), true, true)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
sourceStack.decrement(1);
|
||||
inventory.getInvStack(bestSlot.getLeft()).increment(1);
|
||||
inventory.setChanged();
|
||||
|
||||
return Optional.of(getCraftingMatrix());
|
||||
}
|
||||
|
||||
private CraftingInventory getCraftingMatrix() {
|
||||
if (craftCache == null) {
|
||||
craftCache = new CraftingInventory(new RollingBEContainer(), 3, 3);
|
||||
}
|
||||
if (inventory.hasChanged()) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
craftCache.setInvStack(i, inventory.getInvStack(i).copy());
|
||||
}
|
||||
inventory.resetChanged();
|
||||
}
|
||||
return craftCache;
|
||||
}
|
||||
|
||||
public boolean canMake(CraftingInventory craftMatrix) {
|
||||
ItemStack stack = RollingMachineRecipe.instance.findMatchingRecipeOutput(craftMatrix, this.world);
|
||||
if (locked) {
|
||||
for (int i = 0; i < craftMatrix.getInvSize(); i++) {
|
||||
ItemStack stack1 = craftMatrix.getInvStack(i);
|
||||
if (!stack1.isEmpty() && stack1.getCount() < 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
ItemStack output = inventory.getInvStack(outputSlot);
|
||||
if (output.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return ItemUtils.isItemEqual(stack, output, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.ROLLING_MACHINE.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
this.isRunning = tagCompound.getBoolean("isRunning");
|
||||
this.tickTime = tagCompound.getInt("tickTime");
|
||||
this.locked = tagCompound.getBoolean("locked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tagCompound.putBoolean("isRunning", this.isRunning);
|
||||
tagCompound.putInt("tickTime", this.tickTime);
|
||||
tagCompound.putBoolean("locked", locked);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<RollingMachineBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public int getBurnTime() {
|
||||
return tickTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(final int burnTime) {
|
||||
this.tickTime = burnTime;
|
||||
}
|
||||
|
||||
public int getBurnTimeRemainingScaled(final int scale) {
|
||||
if (tickTime == 0 || Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return tickTime * scale / Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("rollingmachine").player(player.inventory)
|
||||
.inventory().hotbar()
|
||||
.addInventory().blockEntity(this)
|
||||
.slot(0, 30, 22).slot(1, 48, 22).slot(2, 66, 22)
|
||||
.slot(3, 30, 40).slot(4, 48, 40).slot(5, 66, 40)
|
||||
.slot(6, 30, 58).slot(7, 48, 58).slot(8, 66, 58)
|
||||
.onCraft(inv -> this.inventory.setInvStack(1, RollingMachineRecipe.instance.findMatchingRecipeOutput(getCraftingMatrix(), this.world)))
|
||||
.outputSlot(9, 124, 40)
|
||||
.energySlot(10, 8, 70)
|
||||
.syncEnergyValue().syncIntegerValue(this::getBurnTime, this::setBurnTime).syncIntegerValue(this::getLockedInt, this::setLockedInt).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
//Easyest way to sync back to the client
|
||||
public int getLockedInt() {
|
||||
return locked ? 1 : 0;
|
||||
}
|
||||
|
||||
public void setLockedInt(int lockedInt) {
|
||||
locked = lockedInt == 1;
|
||||
}
|
||||
|
||||
public int getProgressScaled(final int scale) {
|
||||
if (tickTime != 0 && Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1) != 0) {
|
||||
return tickTime * scale / Math.max((int) (runTime* (1.0 - getSpeedMultiplier())), 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static class RollingBEContainer extends Container {
|
||||
|
||||
protected RollingBEContainer() {
|
||||
super(null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(final PlayerEntity entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.api.recipe.ScrapboxRecipeCrafter;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.GenericMachineBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ScrapboxinatorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorMaxInput", comment = "Scrapboxinator Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorMaxEnergy", comment = "Scrapboxinator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 1_000;
|
||||
|
||||
public ScrapboxinatorBlockEntity() {
|
||||
super(TRBlockEntities.SCRAPBOXINATOR, "Scrapboxinator", maxInput, maxEnergy, TRContent.Machine.SCRAPBOXINATOR.block, 2);
|
||||
final int[] inputs = new int[] { 0 };
|
||||
final int[] outputs = new int[] { 1 };
|
||||
this.inventory = new RebornInventory<>(3, "ScrapboxinatorBlockEntity", 64, this).withConfiguredAccess();
|
||||
this.crafter = new ScrapboxRecipeCrafter(this, this.inventory, inputs, outputs);
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("scrapboxinator").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).filterSlot(0, 55, 45, stack -> stack.getItem() == TRContent.SCRAP_BOX).outputSlot(1, 101, 45)
|
||||
.energySlot(2, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class ChunkLoaderBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxInput", comment = "Chunk Loader Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
@ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderMaxEnergy", comment = "Chunk Loader Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000;
|
||||
// @ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderWrenchDropRate", comment = "Chunk Loader Wrench Drop Rate")
|
||||
public static float wrenchDropRate = 1.0F;
|
||||
|
||||
public RebornInventory<ChunkLoaderBlockEntity> inventory = new RebornInventory<>(1, "ChunkLoaderBlockEntity", 64, this).withConfiguredAccess();
|
||||
|
||||
public boolean isRunning;
|
||||
public int tickTime;
|
||||
|
||||
public ChunkLoaderBlockEntity() {
|
||||
super(TRBlockEntities.CHUNK_LOADER );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.CHUNK_LOADER.getStack();
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(final Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(final Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<ChunkLoaderBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("chunkloader").player(player.inventory).inventory(8,84).hotbar(8,142).addInventory()
|
||||
.create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
public class CreativeQuantumChestBlockEntity extends QuantumChestBlockEntity {
|
||||
|
||||
public CreativeQuantumChestBlockEntity() {
|
||||
super(TRBlockEntities.CREATIVE_QUANTUM_CHEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
ItemStack stack = inventory.getInvStack(1);
|
||||
if (!stack.isEmpty() && storedItem.isEmpty()) {
|
||||
stack.setCount(stack.getMaxCount());
|
||||
storedItem = stack.copy();
|
||||
}
|
||||
|
||||
storedItem.setCount(maxCapacity - storedItem.getMaxCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int slotTransferSpeed() {
|
||||
return 1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
public class CreativeQuantumTankBlockEntity extends QuantumTankBlockEntity {
|
||||
|
||||
public CreativeQuantumTankBlockEntity() {
|
||||
super(TRBlockEntities.CREATIVE_QUANTUM_TANK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!tank.isEmpty() && !tank.isFull()) {
|
||||
tank.setFluidAmount(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int slotTransferSpeed() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidTransferAmount() {
|
||||
return 10000;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "matter_fabricator", key = "MatterFabricatorMaxInput", comment = "Matter Fabricator Max Input (Value in EU)")
|
||||
public static int maxInput = 8192;
|
||||
@ConfigRegistry(config = "machines", category = "matter_fabricator", key = "MatterFabricatorMaxEnergy", comment = "Matter Fabricator Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 10_000_000;
|
||||
@ConfigRegistry(config = "machines", category = "matter_fabricator", key = "MatterFabricatorFabricationRate", comment = "Matter Fabricator Fabrication Rate, amount of amplifier units per UUM")
|
||||
public static int fabricationRate = 6_000;
|
||||
@ConfigRegistry(config = "machines", category = "matter_fabricator", key = "MatterFabricatorEnergyPerAmp", comment = "Matter Fabricator EU per amplifier unit, multiply this with the rate for total EU")
|
||||
public static int energyPerAmp = 5;
|
||||
|
||||
public RebornInventory<MatterFabricatorBlockEntity> inventory = new RebornInventory<>(12, "MatterFabricatorBlockEntity", 64, this).withConfiguredAccess();
|
||||
private int amplifier = 0;
|
||||
|
||||
public MatterFabricatorBlockEntity() {
|
||||
super(TRBlockEntities.MATTER_FABRICATOR );
|
||||
}
|
||||
|
||||
private boolean spaceForOutput() {
|
||||
for (int i = 6; i < 11; i++) {
|
||||
if (spaceForOutput(i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean spaceForOutput(int slot) {
|
||||
return inventory.getInvStack(slot).isEmpty()
|
||||
|| ItemUtils.isItemEqual(inventory.getInvStack(slot), TRContent.Parts.UU_MATTER.getStack(), true, true)
|
||||
&& inventory.getInvStack(slot).getCount() < 64;
|
||||
}
|
||||
|
||||
private void addOutputProducts() {
|
||||
for (int i = 6; i < 11; i++) {
|
||||
if (spaceForOutput(i)) {
|
||||
addOutputProducts(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addOutputProducts(int slot) {
|
||||
if (inventory.getInvStack(slot).isEmpty()) {
|
||||
inventory.setInvStack(slot, TRContent.Parts.UU_MATTER.getStack());
|
||||
}
|
||||
else if (ItemUtils.isItemEqual(this.inventory.getInvStack(slot), TRContent.Parts.UU_MATTER.getStack(), true, true)) {
|
||||
inventory.getInvStack(slot).setCount((Math.min(64, 1 + inventory.getInvStack(slot).getCount())));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) {
|
||||
if (getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
|
||||
return false;
|
||||
} else {
|
||||
setEnergy(getEnergy() - aEnergy);
|
||||
if (getEnergy() < 0) {
|
||||
setEnergy(0);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getValue(ItemStack itemStack) {
|
||||
if (itemStack.isItemEqualIgnoreDamage(TRContent.Parts.SCRAP.getStack())) {
|
||||
return 200;
|
||||
} else if (itemStack.getItem() == TRContent.SCRAP_BOX) {
|
||||
return 2000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return amplifier;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
amplifier = progress;
|
||||
}
|
||||
|
||||
public int getProgressScaled(int scale) {
|
||||
if (amplifier != 0) {
|
||||
return Math.min(amplifier * scale / fabricationRate, 100);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.tick();
|
||||
this.charge(11);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
final ItemStack stack = inventory.getInvStack(i);
|
||||
if (!stack.isEmpty() && spaceForOutput()) {
|
||||
final int amp = getValue(stack);
|
||||
final int euNeeded = amp * energyPerAmp;
|
||||
if (amp != 0 && this.canUseEnergy(euNeeded)) {
|
||||
useEnergy(euNeeded);
|
||||
amplifier += amp;
|
||||
inventory.shrinkSlot(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (amplifier >= fabricationRate) {
|
||||
if (spaceForOutput()) {
|
||||
addOutputProducts();
|
||||
amplifier -= fabricationRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.MATTER_FABRICATOR.getStack();
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<MatterFabricatorBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
|
||||
return new ContainerBuilder("matterfabricator").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 30, 20).slot(1, 50, 20).slot(2, 70, 20).slot(3, 90, 20).slot(4, 110, 20)
|
||||
.slot(5, 130, 20).outputSlot(6, 40, 66).outputSlot(7, 60, 66).outputSlot(8, 80, 66)
|
||||
.outputSlot(9, 100, 66).outputSlot(10, 120, 66).energySlot(11, 8, 72).syncEnergyValue()
|
||||
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.TechStorageBaseBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class QuantumChestBlockEntity extends TechStorageBaseBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "quantum_chest", key = "QuantumChestMaxStorage", comment = "Maximum amount of items a Quantum Chest can store")
|
||||
public static int maxStorage = Integer.MAX_VALUE;
|
||||
|
||||
public QuantumChestBlockEntity() {
|
||||
this(TRBlockEntities.QUANTUM_CHEST);
|
||||
}
|
||||
|
||||
public QuantumChestBlockEntity(BlockEntityType<?> blockEntityType) {
|
||||
super(blockEntityType, "QuantumChestBlockEntity", maxStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("quantumchest").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.machine.tier3;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class QuantumTankBlockEntity extends MachineBaseBlockEntity
|
||||
implements InventoryProvider, IToolDrop, IListInfoProvider, IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "quantum_tank", key = "QuantumTankMaxStorage", comment = "Maximum amount of millibuckets a Quantum Tank can store")
|
||||
public static int maxStorage = Integer.MAX_VALUE;
|
||||
|
||||
public Tank tank = new Tank("QuantumTankBlockEntity", maxStorage, this);
|
||||
public RebornInventory<QuantumTankBlockEntity> inventory = new RebornInventory<>(3, "QuantumTankBlockEntity", 64, this).withConfiguredAccess();
|
||||
|
||||
public QuantumTankBlockEntity(){
|
||||
this(TRBlockEntities.QUANTUM_TANK);
|
||||
}
|
||||
|
||||
public QuantumTankBlockEntity(BlockEntityType<?> blockEntityTypeIn) {
|
||||
super(blockEntityTypeIn);
|
||||
}
|
||||
|
||||
public void readWithoutCoords(final CompoundTag tagCompound) {
|
||||
tank.read(tagCompound);
|
||||
}
|
||||
|
||||
public CompoundTag writeWithoutCoords(final CompoundTag tagCompound) {
|
||||
tank.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT() {
|
||||
final CompoundTag blockEntity = new CompoundTag();
|
||||
final ItemStack dropStack = TRContent.Machine.QUANTUM_TANK.getStack();
|
||||
this.writeWithoutCoords(blockEntity);
|
||||
dropStack.setTag(new CompoundTag());
|
||||
dropStack.getTag().put("blockEntity", blockEntity);
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!world.isClient) {
|
||||
// TODO: Fix in 1.13
|
||||
// if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|
||||
// || FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType())) {
|
||||
// this.syncWithAll();
|
||||
// }
|
||||
|
||||
}
|
||||
tank.compareAndUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(final CompoundTag tagCompound) {
|
||||
super.fromTag(tagCompound);
|
||||
readWithoutCoords(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(final CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
writeWithoutCoords(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<QuantumTankBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
|
||||
return this.getDropWithNBT();
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
||||
if (isReal | hasData) {
|
||||
if (this.tank.getFluid() != null) {
|
||||
info.add(new LiteralText(this.tank.getFluidAmount() + " of " + this.tank.getFluidType().getName()));
|
||||
} else {
|
||||
info.add(new LiteralText("Empty"));
|
||||
}
|
||||
}
|
||||
info.add(new LiteralText("Capacity " + this.tank.getCapacity() + " mb"));
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("quantumtank").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53).addInventory()
|
||||
.create(this, syncID);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.api.blockentity.IUpgrade;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "aesu", key = "AesuMaxInput", comment = "AESU Max Input (Value in EU)")
|
||||
public static int maxInput = 16192;
|
||||
@ConfigRegistry(config = "machines", category = "aesu", key = "AesuMaxOutput", comment = "AESU Max Output (Value in EU)")
|
||||
public static int maxOutput = 16192;
|
||||
@ConfigRegistry(config = "machines", category = "aesu", key = "AesuMaxEnergy", comment = "AESU Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 100_000_000;
|
||||
|
||||
public RebornInventory<AdjustableSUBlockEntity> inventory = new RebornInventory<>(4, "AdjustableSUBlockEntity", 64, this).withConfiguredAccess();
|
||||
private int OUTPUT = 64; // The current output
|
||||
public int superconductors = 0;
|
||||
|
||||
public AdjustableSUBlockEntity() {
|
||||
super(TRBlockEntities.ADJUSTABLE_SU, "ADJUSTABLE_SU", 4, TRContent.Machine.ADJUSTABLE_SU.block, EnumPowerTier.INSANE, maxInput, maxOutput, maxEnergy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (OUTPUT > getMaxConfigOutput()) {
|
||||
OUTPUT = getMaxConfigOutput();
|
||||
}
|
||||
if(world.getTime() % 20 == 0){
|
||||
checkTier();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxConfigOutput(){
|
||||
int extra = 0;
|
||||
if(superconductors > 0){
|
||||
extra = (int) Math.pow(2, (superconductors + 2)) * maxOutput;
|
||||
}
|
||||
return maxOutput + extra;
|
||||
}
|
||||
|
||||
public void handleGuiInputFromClient(int id, boolean shift, boolean ctrl) {
|
||||
if (id == 300) {
|
||||
OUTPUT += shift ? 4096 : 256;
|
||||
if(ctrl){
|
||||
//Set to max, limited to the max later
|
||||
OUTPUT = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
if (id == 301) {
|
||||
OUTPUT += shift ? 512 : 64;
|
||||
}
|
||||
if (id == 302) {
|
||||
OUTPUT -= shift ? 512 : 64;
|
||||
}
|
||||
if (id == 303) {
|
||||
OUTPUT -= shift ? 4096 : 256;
|
||||
if(ctrl){
|
||||
OUTPUT = 1;
|
||||
}
|
||||
}
|
||||
if (OUTPUT > getMaxConfigOutput()) {
|
||||
OUTPUT = getMaxConfigOutput();
|
||||
}
|
||||
if (OUTPUT <= -1) {
|
||||
OUTPUT = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT() {
|
||||
CompoundTag blockEntity = new CompoundTag();
|
||||
ItemStack dropStack = TRContent.Machine.ADJUSTABLE_SU.getStack();
|
||||
toTag(blockEntity);
|
||||
dropStack.setTag(new CompoundTag());
|
||||
dropStack.getTag().put("blockEntity", blockEntity);
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
public int getCurrentOutput() {
|
||||
return OUTPUT;
|
||||
}
|
||||
|
||||
public void setCurentOutput(int output) {
|
||||
this.OUTPUT = output;
|
||||
}
|
||||
|
||||
// TileEnergyStorage
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return getDropWithNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return OUTPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxOutput() {
|
||||
return OUTPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
//If we have super conductors increase the max input of the machine
|
||||
if(getMaxConfigOutput() > maxOutput){
|
||||
return getMaxConfigOutput();
|
||||
}
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tagCompound) {
|
||||
super.toTag(tagCompound);
|
||||
tagCompound.putInt("output", OUTPUT);
|
||||
inventory.write(tagCompound);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag nbttagcompound) {
|
||||
super.fromTag(nbttagcompound);
|
||||
this.OUTPUT = nbttagcompound.getInt("output");
|
||||
inventory.read(nbttagcompound);
|
||||
}
|
||||
|
||||
// IContainerProvider
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, PlayerEntity player) {
|
||||
return new ContainerBuilder("aesu").player(player.inventory).inventory().hotbar().armor()
|
||||
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
|
||||
.syncEnergyValue().syncIntegerValue(this::getCurrentOutput, this::setCurentOutput).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpgradeValid(IUpgrade upgrade, ItemStack stack) {
|
||||
return stack.isItemEqual(new ItemStack(TRContent.Upgrades.SUPERCONDUCTOR.item));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.powerSystem.ExternalPowerSystems;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blocks.storage.BlockEnergyStorage;
|
||||
|
||||
/**
|
||||
* Created by Rushmead
|
||||
*/
|
||||
public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, InventoryProvider {
|
||||
|
||||
public RebornInventory<EnergyStorageBlockEntity> inventory;
|
||||
public String name;
|
||||
public Block wrenchDrop;
|
||||
public EnumPowerTier tier;
|
||||
public int maxInput;
|
||||
public int maxOutput;
|
||||
public int maxStorage;
|
||||
|
||||
public EnergyStorageBlockEntity(BlockEntityType<?> blockEntityType, String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxInput, int maxOuput, int maxStorage) {
|
||||
super(blockEntityType);
|
||||
inventory = new RebornInventory<>(invSize, name + "BlockEntity", 64, this).withConfiguredAccess();
|
||||
this.wrenchDrop = wrenchDrop;
|
||||
this.tier = tier;
|
||||
this.name = name;
|
||||
this.maxInput = maxInput;
|
||||
this.maxOutput = maxOuput;
|
||||
this.maxStorage = maxStorage;
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!inventory.getInvStack(0).isEmpty()) {
|
||||
ItemStack stack = inventory.getInvStack(0);
|
||||
|
||||
if (ExternalPowerSystems.isPoweredItem(stack)) {
|
||||
ExternalPowerSystems.chargeItem(this, stack);
|
||||
}
|
||||
}
|
||||
if (!inventory.getInvStack(1).isEmpty()) {
|
||||
charge(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
return getFacing() != direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
return getFacing() == direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void setFacing(Direction enumFacing) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockEnergyStorage.FACING, enumFacing));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getFacingEnum() {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (block instanceof BlockEnergyStorage) {
|
||||
return ((BlockEnergyStorage) block).getFacing(world.getBlockState(pos));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return new ItemStack(wrenchDrop);
|
||||
}
|
||||
|
||||
// ItemHandlerProvider
|
||||
@Override
|
||||
public RebornInventory<EnergyStorageBlockEntity> getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 14/03/2016.
|
||||
*
|
||||
*/
|
||||
public class HighVoltageSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider {
|
||||
|
||||
/**
|
||||
* MFSU should store 40M FE with 2048 FE/t I/O
|
||||
*/
|
||||
public HighVoltageSUBlockEntity() {
|
||||
super(TRBlockEntities.HIGH_VOLTAGE_SU, "HIGH_VOLTAGE_SU", 2, TRContent.Machine.HIGH_VOLTAGE_SU.block, EnumPowerTier.HIGH, 512, 512, 10_000_000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("mfsu").player(player.inventory).inventory().hotbar().armor()
|
||||
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
|
||||
.syncEnergyValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 14/03/2016.
|
||||
*/
|
||||
public class LowVoltageSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider {
|
||||
|
||||
public LowVoltageSUBlockEntity() {
|
||||
super(TRBlockEntities.LOW_VOLTAGE_SU, "BatBox", 2, TRContent.Machine.LOW_VOLTAGE_SU.block, EnumPowerTier.LOW, 32, 32, 40000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("batbox").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue().addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 14/03/2016.
|
||||
*
|
||||
*/
|
||||
public class MediumVoltageSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider {
|
||||
|
||||
/**
|
||||
* MFE should store 1.2M FE with 512 FE/t I/O
|
||||
*/
|
||||
public MediumVoltageSUBlockEntity() {
|
||||
super(TRBlockEntities.MEDIUM_VOLTAGE_SU, "MEDIUM_VOLTAGE_SU", 2, TRContent.Machine.MEDIUM_VOLTAGE_SU.block, EnumPowerTier.MEDIUM, 128, 128, 300000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("mfe").player(player.inventory).inventory().hotbar().armor()
|
||||
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
|
||||
.syncEnergyValue().addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.idsu;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class IDSUManager {
|
||||
public static IDataIDSU getData(World world) {
|
||||
throw new UnsupportedOperationException("needs rewriting anyway");
|
||||
// IDSUSaveManger instance = (IDSUSaveManger) storage.getOrLoadData(IDSUSaveManger.class, TechReborn.MOD_ID + "_IDSU");
|
||||
//
|
||||
// if (instance == null) {
|
||||
// instance = new IDSUSaveManger(TechReborn.MOD_ID + "_IDSU");
|
||||
// storage.setData(TechReborn.MOD_ID + "_IDSU", instance);
|
||||
// }
|
||||
// return instance;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.idsu;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.PersistentState;
|
||||
import techreborn.TechReborn;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 13/06/2017.
|
||||
*/
|
||||
public class IDSUSaveManger extends PersistentState implements IDataIDSU {
|
||||
public IDSUSaveManger(String name) {
|
||||
super(TechReborn.MOD_ID + "_IDSU");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag nbt) {
|
||||
power = nbt.getDouble("power");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag compound) {
|
||||
compound.putDouble("power", power);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
double power;
|
||||
|
||||
@Override
|
||||
public double getStoredPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredPower(double storedPower) {
|
||||
power = storedPower;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.idsu;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 13/06/2017.
|
||||
*/
|
||||
public interface IDataIDSU {
|
||||
|
||||
public double getStoredPower();
|
||||
|
||||
public void setStoredPower(double storedPower);
|
||||
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.idsu;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.storage.EnergyStorageBlockEntity;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxInput", comment = "IDSU Max Input (Value in EU)")
|
||||
public static int maxInput = 8192;
|
||||
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxOutput", comment = "IDSU Max Output (Value in EU)")
|
||||
public static int maxOutput = 8192;
|
||||
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxEnergy", comment = "IDSU Max Energy (Value in EU)")
|
||||
public static int maxEnergy = 100_000_000;
|
||||
|
||||
public String ownerUdid;
|
||||
|
||||
public InterdimensionalSUBlockEntity() {
|
||||
super(TRBlockEntities.INTERDIMENSIONAL_SU, "IDSU", 2, TRContent.Machine.INTERDIMENSIONAL_SU.block, EnumPowerTier.EXTREME, maxInput, maxOutput, maxEnergy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy() {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
return IDSUManager.getData(world).getStoredPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy) {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
IDSUManager.getData(world).setStoredPower(energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double useEnergy(double extract, boolean simulate) {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
double energy = IDSUManager.getData(world).getStoredPower();
|
||||
if (extract > energy) {
|
||||
extract = energy;
|
||||
}
|
||||
if (!simulate) {
|
||||
setEnergy(energy - extract);
|
||||
}
|
||||
return extract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseEnergy(double input) {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return input <= IDSUManager.getData(world).getStoredPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag nbttagcompound) {
|
||||
super.fromTag(nbttagcompound);
|
||||
this.ownerUdid = nbttagcompound.getString("ownerUdid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag nbttagcompound) {
|
||||
super.toTag(nbttagcompound);
|
||||
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
||||
return nbttagcompound;
|
||||
}
|
||||
nbttagcompound.putString("ownerUdid", this.ownerUdid);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("idsu").player(player.inventory).inventory().hotbar().armor()
|
||||
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
|
||||
.syncEnergyValue().addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHanldeEnergyNBT() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.lesu;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
public class LSUStorageBlockEntity extends MachineBaseBlockEntity
|
||||
implements IToolDrop {
|
||||
|
||||
public LesuNetwork network;
|
||||
|
||||
public LSUStorageBlockEntity() {
|
||||
super(TRBlockEntities.LSU_STORAGE);
|
||||
}
|
||||
|
||||
public final void findAndJoinNetwork(World world, int x, int y, int z) {
|
||||
network = new LesuNetwork();
|
||||
network.addElement(this);
|
||||
for (Direction direction : Direction.values()) {
|
||||
if (world.getBlockEntity(new BlockPos(x + direction.getOffsetX(), y + direction.getOffsetY(),
|
||||
z + direction.getOffsetZ())) instanceof LSUStorageBlockEntity) {
|
||||
LSUStorageBlockEntity lesu = (LSUStorageBlockEntity) world.getBlockEntity(new BlockPos(x + direction.getOffsetX(),
|
||||
y + direction.getOffsetY(), z + direction.getOffsetZ()));
|
||||
if (lesu.network != null) {
|
||||
lesu.network.merge(network);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void setNetwork(LesuNetwork n) {
|
||||
if (n == null) {
|
||||
} else {
|
||||
network = n;
|
||||
network.addElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final void resetNetwork() {
|
||||
network = null;
|
||||
}
|
||||
|
||||
public final void removeFromNetwork() {
|
||||
if (network == null) {
|
||||
} else
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
public final void rebuildNetwork() {
|
||||
removeFromNetwork();
|
||||
resetNetwork();
|
||||
findAndJoinNetwork(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (network == null) {
|
||||
findAndJoinNetwork(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
} else {
|
||||
if (network.master != null
|
||||
&& network.master.getWorld().getBlockEntity(new BlockPos(network.master.getPos().getX(),
|
||||
network.master.getPos().getY(), network.master.getPos().getZ())) != network.master) {
|
||||
network.master = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
|
||||
return TRContent.Machine.LSU_STORAGE.getStack();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.lesu;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.blocks.storage.BlockLapotronicSU;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
import techreborn.blockentity.storage.EnergyStorageBlockEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider{
|
||||
|
||||
// @ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxInput", comment = "LESU Max Input (Value in EU)")
|
||||
// public static int maxInput = 8192;
|
||||
@ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxOutput", comment = "LESU Base Output (Value in EU)")
|
||||
public static int baseOutput = 16;
|
||||
@ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxEnergyPerBlock", comment = "LESU Max Energy Per Block (Value in EU)")
|
||||
public static int storagePerBlock = 1_000_000;
|
||||
@ConfigRegistry(config = "machines", category = "lesu", key = "LesuExtraIO", comment = "LESU Extra I/O Multiplier")
|
||||
public static int extraIOPerBlock = 8;
|
||||
|
||||
public int connectedBlocks = 0;
|
||||
private ArrayList<LesuNetwork> countedNetworks = new ArrayList<>();
|
||||
|
||||
public LapotronicSUBlockEntity() {
|
||||
super(TRBlockEntities.LAPOTRONIC_SU, "LESU", 2, TRContent.Machine.LAPOTRONIC_SU.block, EnumPowerTier.INSANE, 8192, baseOutput, 1_000_000);
|
||||
checkOverfill = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
countedNetworks.clear();
|
||||
connectedBlocks = 0;
|
||||
for (Direction dir : Direction.values()) {
|
||||
BlockPos adjucentBlockPos = new BlockPos(pos.getX() + dir.getOffsetX(),
|
||||
pos.getY() + dir.getOffsetX(), pos.getZ() + dir.getOffsetX());
|
||||
BlockEntity adjucent = world.getBlockEntity(adjucentBlockPos);
|
||||
if (adjucent == null || !(adjucent instanceof LSUStorageBlockEntity)) {
|
||||
continue;
|
||||
}
|
||||
if (((LSUStorageBlockEntity) adjucent).network == null) {
|
||||
continue;
|
||||
}
|
||||
LesuNetwork network = ((LSUStorageBlockEntity) adjucent).network;
|
||||
if (!countedNetworks.contains(network)) {
|
||||
if (network.master == null || network.master == this) {
|
||||
connectedBlocks += network.storages.size();
|
||||
countedNetworks.add(network);
|
||||
network.master = this;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
setMaxStorage();
|
||||
maxOutput = (connectedBlocks * extraIOPerBlock) + baseOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getFacingEnum() {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (block instanceof BlockLapotronicSU) {
|
||||
return ((BlockLapotronicSU) block).getFacing(world.getBlockState(pos));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getOutputRate() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
public void setOutputRate(int output) {
|
||||
this.maxOutput = output;
|
||||
}
|
||||
|
||||
public int getConnectedBlocksNum() {
|
||||
return connectedBlocks;
|
||||
}
|
||||
|
||||
public void setConnectedBlocksNum(int value) {
|
||||
this.connectedBlocks = value;
|
||||
if (world.isClient) {
|
||||
setMaxStorage();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxStorage(){
|
||||
maxStorage = (connectedBlocks + 1) * storagePerBlock;
|
||||
if (maxStorage < 0 || maxStorage > Integer.MAX_VALUE / RebornCoreConfig.euPerFU) {
|
||||
maxStorage = Integer.MAX_VALUE / RebornCoreConfig.euPerFU;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("lesu").player(player.inventory).inventory().hotbar().armor().complete(8, 18)
|
||||
.addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue()
|
||||
.syncIntegerValue(this::getOutputRate, this::setOutputRate)
|
||||
.syncIntegerValue(this::getConnectedBlocksNum, this::setConnectedBlocksNum).addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.storage.lesu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LesuNetwork {
|
||||
|
||||
public ArrayList<LSUStorageBlockEntity> storages = new ArrayList<>();
|
||||
|
||||
public LapotronicSUBlockEntity master;
|
||||
|
||||
public void addElement(LSUStorageBlockEntity lesuStorage) {
|
||||
if (!storages.contains(lesuStorage) && storages.size() < 5000) {
|
||||
storages.add(lesuStorage);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeElement(LSUStorageBlockEntity lesuStorage) {
|
||||
storages.remove(lesuStorage);
|
||||
rebuild();
|
||||
}
|
||||
|
||||
private void rebuild() {
|
||||
master = null;
|
||||
for (LSUStorageBlockEntity lesuStorage : storages) {
|
||||
lesuStorage.findAndJoinNetwork(lesuStorage.getWorld(), lesuStorage.getPos().getX(),
|
||||
lesuStorage.getPos().getY(), lesuStorage.getPos().getZ());
|
||||
}
|
||||
}
|
||||
|
||||
public void merge(LesuNetwork network) {
|
||||
if (network != this) {
|
||||
ArrayList<LSUStorageBlockEntity> blockEntityLesuStorages = new ArrayList<>();
|
||||
blockEntityLesuStorages.addAll(network.storages);
|
||||
network.clear(false);
|
||||
for (LSUStorageBlockEntity lesuStorage : blockEntityLesuStorages) {
|
||||
lesuStorage.setNetwork(this);
|
||||
}
|
||||
if (network.master != null && this.master == null) {
|
||||
this.master = network.master;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clear(boolean clearBlockEntities) {
|
||||
if (clearBlockEntities) {
|
||||
for (LSUStorageBlockEntity blockEntityLesuStorage : storages) {
|
||||
blockEntityLesuStorage.resetNetwork();
|
||||
}
|
||||
}
|
||||
storages.clear();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.transformers;
|
||||
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 16/03/2016.
|
||||
*/
|
||||
public class HVTransformerBlockEntity extends TransformerBlockEntity {
|
||||
|
||||
public HVTransformerBlockEntity() {
|
||||
super(TRBlockEntities.HV_TRANSFORMER, "HVTransformer", TRContent.Machine.HV_TRANSFORMER.block, EnumPowerTier.EXTREME);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.transformers;
|
||||
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 16/03/2016.
|
||||
*/
|
||||
public class LVTransformerBlockEntity extends TransformerBlockEntity {
|
||||
|
||||
public LVTransformerBlockEntity() {
|
||||
super(TRBlockEntities.LV_TRANSFORMER, "LVTransformer", TRContent.Machine.LV_TRANSFORMER.block, EnumPowerTier.MEDIUM);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.transformers;
|
||||
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import techreborn.init.TRContent;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 16/03/2016.
|
||||
*/
|
||||
public class MVTransformerBlockEntity extends TransformerBlockEntity {
|
||||
|
||||
public MVTransformerBlockEntity() {
|
||||
super(TRBlockEntities.MV_TRANSFORMER, "MVTransformer", TRContent.Machine.MV_TRANSFORMER.block, EnumPowerTier.HIGH);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blockentity.transformers;
|
||||
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.registration.RebornRegister;
|
||||
import reborncore.common.registration.config.ConfigRegistry;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.blocks.transformers.BlockTransformer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Rushmead
|
||||
*/
|
||||
@RebornRegister(TechReborn.MOD_ID)
|
||||
public class TransformerBlockEntity extends PowerAcceptorBlockEntity
|
||||
implements IToolDrop, IListInfoProvider {
|
||||
|
||||
@ConfigRegistry(config = "misc", category = "general", key = "IC2TransformersStyle", comment = "Input from dots side, output from other sides, like in IC2.")
|
||||
public static boolean IC2TransformersStyle = true;
|
||||
|
||||
public String name;
|
||||
public Block wrenchDrop;
|
||||
public EnumPowerTier inputTier;
|
||||
public EnumPowerTier ouputTier;
|
||||
public int maxInput;
|
||||
public int maxOutput;
|
||||
public int maxStorage;
|
||||
|
||||
public TransformerBlockEntity(BlockEntityType<?> blockEntityType, String name, Block wrenchDrop, EnumPowerTier tier) {
|
||||
super(blockEntityType);
|
||||
this.wrenchDrop = wrenchDrop;
|
||||
this.inputTier = tier;
|
||||
if (tier != EnumPowerTier.MICRO) {
|
||||
ouputTier = EnumPowerTier.values()[tier.ordinal() - 1];
|
||||
} else {
|
||||
ouputTier = EnumPowerTier.MICRO;
|
||||
}
|
||||
this.name = name;
|
||||
this.maxInput = tier.getMaxInput();
|
||||
this.maxOutput = tier.getMaxOutput();
|
||||
this.maxStorage = tier.getMaxInput() * 2;
|
||||
|
||||
// Should always be 4, except if we're tier MICRO, in which it will be 1.
|
||||
super.setMaxPacketsPerTick(tier.getMaxOutput() / ouputTier.getMaxInput());
|
||||
}
|
||||
|
||||
// TilePowerAcceptor
|
||||
@Override
|
||||
public double getBaseMaxPower() {
|
||||
return maxStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptEnergy(Direction direction) {
|
||||
if (IC2TransformersStyle == true){
|
||||
return getFacingEnum() == direction;
|
||||
}
|
||||
return getFacingEnum() != direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(Direction direction) {
|
||||
if (IC2TransformersStyle == true){
|
||||
return getFacingEnum() != direction;
|
||||
}
|
||||
return getFacing() == direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return ouputTier.getMaxOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseMaxInput() {
|
||||
return inputTier.getMaxInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumPowerTier getPushingTier() {
|
||||
return ouputTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTier() {
|
||||
//Nope
|
||||
//TODO: really nope? needs review
|
||||
}
|
||||
|
||||
// TileMachineBase
|
||||
@Override
|
||||
public Direction getFacingEnum() {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (block instanceof BlockTransformer) {
|
||||
return ((BlockTransformer) block).getFacing(world.getBlockState(pos));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||
return new ItemStack(wrenchDrop);
|
||||
}
|
||||
|
||||
// IListInfoProvider
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
info.add(new LiteralText(Formatting.GRAY + "Input Rate: " + Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted((int) getMaxInput())));
|
||||
info.add(new LiteralText(Formatting.GRAY + "Input Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(inputTier.toString())));
|
||||
info.add(new LiteralText(Formatting.GRAY + "Output Rate: " + Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted((int) getMaxOutput())));
|
||||
info.add(new LiteralText(Formatting.GRAY + "Output Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(ouputTier.toString())));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue