2015-11-14 21:27:36 +01:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockAtomicReconstructor.java") is part of the Actually Additions mod for Minecraft.
|
2015-11-14 21:27:36 +01:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-11-14 21:27:36 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-11-14 21:27:36 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2021-02-27 21:24:26 +01:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
|
2021-02-28 12:33:01 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.FullyDirectionalBlock;
|
2021-11-14 19:18:07 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
|
2016-07-07 17:59:45 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2021-02-28 11:35:10 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Lang;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-07-07 17:59:45 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.client.MainWindow;
|
2015-12-21 22:28:57 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2016-05-05 00:06:02 +02:00
|
|
|
import net.minecraft.item.Item;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.item.Items;
|
|
|
|
import net.minecraft.state.DirectionProperty;
|
|
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.util.ActionResultType;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.util.Hand;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2017-08-08 20:28:30 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2021-02-27 21:24:26 +01:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2022-06-24 21:38:07 +02:00
|
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.world.IBlockReader;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.world.World;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2021-02-26 22:15:48 +01:00
|
|
|
|
2021-02-27 17:22:03 +01:00
|
|
|
import javax.annotation.Nullable;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2021-02-28 12:33:01 +01:00
|
|
|
public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container implements IHudDisplay {
|
2021-02-27 17:22:03 +01:00
|
|
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2016-01-19 21:56:45 +01:00
|
|
|
public static final int NAME_FLAVOR_AMOUNTS_1 = 12;
|
|
|
|
public static final int NAME_FLAVOR_AMOUNTS_2 = 14;
|
|
|
|
|
2021-02-27 13:24:45 +01:00
|
|
|
public BlockAtomicReconstructor() {
|
2021-02-28 15:47:54 +01:00
|
|
|
super(ActuallyBlocks.defaultPickProps(0, 10.0F, 80F));
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-29 13:17:45 +01:00
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
|
|
|
ItemStack heldItem = player.getItemInHand(hand);
|
2021-02-26 22:15:48 +01:00
|
|
|
if (this.tryToggleRedstone(world, pos, player)) {
|
2021-02-27 17:22:03 +01:00
|
|
|
return ActionResultType.PASS;
|
2021-02-26 22:15:48 +01:00
|
|
|
}
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!world.isClientSide) {
|
|
|
|
TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor) world.getBlockEntity(pos);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (reconstructor != null) {
|
2022-06-24 21:23:43 +02:00
|
|
|
if (!heldItem.isEmpty()) {
|
2016-05-05 00:06:02 +02:00
|
|
|
Item item = heldItem.getItem();
|
2022-06-24 21:23:43 +02:00
|
|
|
if (item instanceof ILensItem && reconstructor.inv.getStackInSlot(0).isEmpty()) {
|
2015-12-21 22:18:33 +01:00
|
|
|
ItemStack toPut = heldItem.copy();
|
2018-06-23 01:39:30 +02:00
|
|
|
toPut.setCount(1);
|
|
|
|
reconstructor.inv.setStackInSlot(0, toPut);
|
2022-06-24 21:23:43 +02:00
|
|
|
if (!player.isCreative()) {
|
|
|
|
heldItem.shrink(1);
|
|
|
|
}
|
|
|
|
return ActionResultType.CONSUME;
|
2016-05-05 00:06:02 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2018-06-23 01:39:30 +02:00
|
|
|
ItemStack slot = reconstructor.inv.getStackInSlot(0);
|
2022-06-24 21:23:43 +02:00
|
|
|
if (!slot.isEmpty() && hand == Hand.MAIN_HAND) {
|
2021-08-22 17:09:06 +02:00
|
|
|
player.setItemInHand(hand, slot.copy());
|
2022-06-24 21:23:43 +02:00
|
|
|
reconstructor.inv.setStackInSlot(0, ItemStack.EMPTY);
|
|
|
|
return ActionResultType.CONSUME;
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
2015-11-15 03:15:19 +01:00
|
|
|
}
|
2022-06-24 21:23:43 +02:00
|
|
|
return ActionResultType.FAIL;
|
2015-11-15 03:15:19 +01:00
|
|
|
}
|
2022-06-24 21:23:43 +02:00
|
|
|
return ActionResultType.CONSUME;
|
2015-11-15 03:15:19 +01:00
|
|
|
}
|
2015-11-22 20:23:54 +01:00
|
|
|
|
2021-02-27 17:22:03 +01:00
|
|
|
@Nullable
|
2022-01-19 02:11:23 +01:00
|
|
|
@Override
|
|
|
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
2015-12-01 19:48:09 +01:00
|
|
|
return new TileEntityAtomicReconstructor();
|
|
|
|
}
|
|
|
|
|
2022-01-19 02:11:23 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(BlockState state) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:28:57 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-02-27 21:24:26 +01:00
|
|
|
public void displayHud(MatrixStack matrices, Minecraft minecraft, PlayerEntity player, ItemStack stack, RayTraceResult rayCast, MainWindow resolution) {
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!(rayCast instanceof BlockRayTraceResult) || minecraft.level == null) {
|
2021-02-27 21:24:26 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-02-28 11:35:10 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
TileEntity tile = minecraft.level.getBlockEntity(((BlockRayTraceResult) rayCast).getBlockPos());
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tile instanceof TileEntityAtomicReconstructor) {
|
|
|
|
ItemStack slot = ((TileEntityAtomicReconstructor) tile).inv.getStackInSlot(0);
|
2022-06-24 21:38:07 +02:00
|
|
|
ITextComponent lens_name;
|
|
|
|
if (slot.isEmpty()) {
|
|
|
|
lens_name = new TranslationTextComponent("info.actuallyadditions.nolens");
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2022-06-24 21:38:07 +02:00
|
|
|
lens_name = slot.getItem().getName(slot);
|
2015-12-21 23:53:01 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
AssetUtil.renderStackToGui(slot, resolution.getGuiScaledWidth() / 2 + 15, resolution.getGuiScaledHeight() / 2 - 19, 1F);
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
2022-06-24 21:38:07 +02:00
|
|
|
minecraft.font.drawShadow(matrices, lens_name.plainCopy().withStyle(TextFormatting.YELLOW).withStyle(TextFormatting.ITALIC).getString(), resolution.getGuiScaledWidth() / 2.0f + 35, resolution.getGuiScaledHeight() / 2.0f - 15, 0xFFFFFF);
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 21:56:45 +01:00
|
|
|
|
2021-02-27 17:22:03 +01:00
|
|
|
// public static class TheItemBlock extends ItemBlockBase {
|
|
|
|
//
|
|
|
|
// private long lastSysTime;
|
|
|
|
// private int toPick1;
|
|
|
|
// private int toPick2;
|
|
|
|
//
|
|
|
|
// public TheItemBlock(Block block) {
|
|
|
|
// super(block, new Item.Properties().group(ActuallyAdditions.GROUP).setNoRepair());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
|
|
|
// long sysTime = System.currentTimeMillis();
|
|
|
|
//
|
|
|
|
// if (this.lastSysTime + 3000 < sysTime) {
|
|
|
|
// this.lastSysTime = sysTime;
|
|
|
|
// if (Minecraft.getInstance().world != null) {
|
|
|
|
// this.toPick1 = Minecraft.getInstance().world.rand.nextInt(NAME_FLAVOR_AMOUNTS_1) + 1;
|
|
|
|
// this.toPick2 = Minecraft.getInstance().world.rand.nextInt(NAME_FLAVOR_AMOUNTS_2) + 1;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// String base = "tile." + ActuallyAdditions.MODID + "." + ((BlockAtomicReconstructor) this.block).getBaseName() + ".info.";
|
|
|
|
// tooltip.add(StringUtil.localize(base + "1." + this.toPick1) + " " + StringUtil.localize(base + "2." + this.toPick2));
|
|
|
|
// }
|
|
|
|
// }
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2017-08-08 20:28:30 +02:00
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
public boolean hasAnalogOutputSignal(BlockState state) {
|
2017-08-08 20:28:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
public int getAnalogOutputSignal(BlockState blockState, World world, BlockPos pos) {
|
|
|
|
TileEntity t = world.getBlockEntity(pos);
|
2019-02-27 19:53:05 +01:00
|
|
|
int i = 0;
|
|
|
|
if (t instanceof TileEntityAtomicReconstructor) {
|
|
|
|
i = ((TileEntityAtomicReconstructor) t).getEnergy();
|
|
|
|
}
|
2017-08-08 20:28:30 +02:00
|
|
|
return MathHelper.clamp(i / 20000, 0, 15);
|
|
|
|
}
|
2021-02-26 22:15:48 +01:00
|
|
|
}
|