2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.common.blocks;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
|
2020-09-09 16:49:01 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
|
|
|
|
import de.ellpeck.actuallyadditions.common.config.values.ConfigIntValues;
|
|
|
|
import de.ellpeck.actuallyadditions.common.tile.TileEntityAtomicReconstructor;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
2016-11-26 21:32:27 +01:00
|
|
|
import net.minecraft.block.Block;
|
2020-09-09 16:33:43 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
2020-09-09 10:58:32 +02:00
|
|
|
import net.minecraft.client.MainWindow;
|
2015-12-21 22:28:57 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2017-06-17 00:48:49 +02:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2020-09-09 16:33:43 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-09-09 17:32:40 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.Items;
|
2020-09-09 10:58:32 +02:00
|
|
|
import net.minecraft.state.StateContainer;
|
|
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2020-09-09 10:58:32 +02:00
|
|
|
import net.minecraft.util.ActionResultType;
|
|
|
|
import net.minecraft.util.Hand;
|
2016-11-21 16:23:48 +01:00
|
|
|
import net.minecraft.util.Mirror;
|
|
|
|
import net.minecraft.util.Rotation;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-09-09 16:33:43 +02:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2017-08-08 20:28:30 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2020-09-09 10:58:32 +02:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2020-09-09 10:58:32 +02:00
|
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
2020-09-09 16:33:43 +02:00
|
|
|
import net.minecraft.world.IBlockReader;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.world.World;
|
2020-09-09 16:33:43 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2020-09-08 00:46:45 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class BlockAtomicReconstructor extends BlockContainerBase implements IHudDisplay {
|
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;
|
|
|
|
|
2020-09-08 00:46:45 +02:00
|
|
|
public BlockAtomicReconstructor() {
|
2020-09-09 17:32:40 +02:00
|
|
|
super(STONE_PROPS.hardnessAndResistance(10f, 80f));
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2015-11-15 03:15:19 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit){
|
2016-11-19 21:11:17 +01:00
|
|
|
ItemStack heldItem = player.getHeldItem(hand);
|
2020-09-09 16:33:43 +02:00
|
|
|
if (this.tryToggleRedstone(world, pos, player)) {
|
|
|
|
return ActionResultType.SUCCESS;
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!world.isRemote) {
|
|
|
|
TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor) world.getTileEntity(pos);
|
|
|
|
if (reconstructor != null) {
|
|
|
|
if (StackUtil.isValid(heldItem)) {
|
2016-05-05 00:06:02 +02:00
|
|
|
Item item = heldItem.getItem();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (item instanceof ILensItem && !StackUtil.isValid(reconstructor.inv.getStackInSlot(0))) {
|
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);
|
2015-12-21 22:18:33 +01:00
|
|
|
player.inventory.decrStackSize(player.inventory.currentItem, 1);
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
2016-05-05 00:06:02 +02:00
|
|
|
//Shush, don't tell anyone!
|
2020-09-09 16:33:43 +02:00
|
|
|
else if (ConfigIntValues.ELEVEN.getValue() == 11 && item == Items.MUSIC_DISC_11) {
|
2016-05-05 00:06:02 +02:00
|
|
|
reconstructor.counter++;
|
|
|
|
reconstructor.markDirty();
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2018-06-23 01:39:30 +02:00
|
|
|
ItemStack slot = reconstructor.inv.getStackInSlot(0);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(slot)) {
|
2016-11-17 16:31:05 +01:00
|
|
|
player.setHeldItem(hand, slot.copy());
|
2018-06-23 01:39:30 +02:00
|
|
|
reconstructor.inv.setStackInSlot(0, StackUtil.getEmpty());
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
2015-11-15 03:15:19 +01:00
|
|
|
}
|
|
|
|
}
|
2020-09-09 16:33:43 +02:00
|
|
|
return ActionResultType.SUCCESS;
|
2015-11-15 03:15:19 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public TileEntity createTileEntity(BlockState state, IBlockReader world){
|
2015-12-01 19:48:09 +01:00
|
|
|
return new TileEntityAtomicReconstructor();
|
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2015-12-21 22:28:57 +01:00
|
|
|
@Override
|
2020-09-09 16:33:43 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2020-09-09 10:58:32 +02:00
|
|
|
public void displayHud(Minecraft minecraft, PlayerEntity player, ItemStack stack, BlockRayTraceResult posHit, MainWindow window) {
|
|
|
|
TileEntity tile = minecraft.world.getTileEntity(posHit.getPos());
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tile instanceof TileEntityAtomicReconstructor) {
|
|
|
|
ItemStack slot = ((TileEntityAtomicReconstructor) tile).inv.getStackInSlot(0);
|
2020-09-09 10:58:32 +02:00
|
|
|
ITextComponent displayString;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!StackUtil.isValid(slot)) {
|
2020-09-09 10:58:32 +02:00
|
|
|
displayString = new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".noLens");
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2020-09-09 10:58:32 +02:00
|
|
|
displayString = slot.getItem().getDisplayName(slot);
|
2015-12-21 23:53:01 +01:00
|
|
|
|
2020-09-09 10:58:32 +02:00
|
|
|
AssetUtil.renderStackToGui(slot, window.getScaledWidth() / 2 + 15, window.getScaledHeight() / 2 - 19, 1F);
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + displayString.getFormattedText(), window.getScaledWidth() / 2 + 35, window.getScaledHeight() / 2 - 15, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 21:56:45 +01:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder){
|
|
|
|
builder.add(BlockStateProperties.FACING);
|
2016-11-21 16:23:48 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2016-11-21 16:23:48 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public BlockState rotate(BlockState state, Rotation rot){
|
|
|
|
return state.with(BlockStateProperties.FACING, rot.rotate(state.get(BlockStateProperties.FACING)));
|
2016-11-21 16:23:48 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2016-11-21 16:23:48 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public BlockState mirror(BlockState state, Mirror mirrorIn){
|
|
|
|
return this.rotate(state, mirrorIn.toRotation(state.get(BlockStateProperties.FACING)));
|
2016-11-21 16:23:48 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2016-11-21 16:23:48 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public boolean hasComparatorInputOverride(BlockState state){
|
|
|
|
return true;
|
2016-11-21 16:23:48 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2016-11-21 16:23:48 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public int getComparatorInputOverride(BlockState blockState, World world, BlockPos pos) {
|
|
|
|
TileEntity t = world.getTileEntity(pos);
|
|
|
|
int i = 0;
|
|
|
|
if (t instanceof TileEntityAtomicReconstructor) {
|
|
|
|
i = ((TileEntityAtomicReconstructor) t).getEnergy();
|
|
|
|
}
|
|
|
|
return MathHelper.clamp(i / 20000, 0, 15);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2020-09-09 17:18:09 +02:00
|
|
|
public class BlockItem extends net.minecraft.item.BlockItem {
|
2016-01-19 21:56:45 +01:00
|
|
|
private long lastSysTime;
|
|
|
|
private int toPick1;
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2016-01-19 21:56:45 +01:00
|
|
|
private int toPick2;
|
2020-09-09 10:58:32 +02:00
|
|
|
|
|
|
|
public BlockItem() {
|
|
|
|
super(BlockAtomicReconstructor.this, new Properties());
|
2016-01-19 21:56:45 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2016-01-19 21:56:45 +01:00
|
|
|
@Override
|
2020-09-09 10:58:32 +02:00
|
|
|
public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag){
|
2016-01-19 21:56:45 +01:00
|
|
|
long sysTime = System.currentTimeMillis();
|
2020-09-09 10:58:32 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.lastSysTime + 3000 < sysTime) {
|
2016-01-19 21:56:45 +01:00
|
|
|
this.lastSysTime = sysTime;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (world != null) {
|
|
|
|
this.toPick1 = world.rand.nextInt(NAME_FLAVOR_AMOUNTS_1) + 1;
|
|
|
|
this.toPick2 = world.rand.nextInt(NAME_FLAVOR_AMOUNTS_2) + 1;
|
2017-06-17 00:48:49 +02:00
|
|
|
}
|
2016-01-19 21:56:45 +01:00
|
|
|
}
|
2020-09-09 10:58:32 +02:00
|
|
|
|
|
|
|
String base = String.format("tile.%s.%s.info", ActuallyAdditions.MODID, BlockAtomicReconstructor.this.getRegistryName().getPath());
|
|
|
|
tooltip.add(new TranslationTextComponent(String.format("%s1.%s", base, this.toPick1)).appendSibling(new TranslationTextComponent(String.format("%s2.%s", base, this.toPick2))));
|
2016-01-19 21:56:45 +01:00
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2017-08-08 20:28:30 +02:00
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|