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
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
2016-01-19 21:56:45 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
|
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;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
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;
|
2016-11-26 21:32:27 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockDirectional;
|
|
|
|
import net.minecraft.block.SoundType;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-11-21 16:23:48 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-12-21 22:28:57 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-11-15 03:15:19 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-05-05 00:06:02 +02:00
|
|
|
import net.minecraft.init.Items;
|
2015-12-06 02:16:52 +01:00
|
|
|
import net.minecraft.item.EnumRarity;
|
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;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumHand;
|
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;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2015-11-14 21:27:36 +01:00
|
|
|
import net.minecraft.world.World;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2016-01-19 21:56:45 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-21 22:28:57 +01: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;
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public BlockAtomicReconstructor(String name){
|
2016-04-20 21:39:03 +02:00
|
|
|
super(Material.ROCK, name);
|
2015-11-14 21:27:36 +01:00
|
|
|
this.setHarvestLevel("pickaxe", 0);
|
2015-11-27 17:00:58 +01:00
|
|
|
this.setHardness(10F);
|
|
|
|
this.setResistance(80F);
|
2016-04-20 21:39:03 +02:00
|
|
|
this.setSoundType(SoundType.STONE);
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-29 13:17:45 +01:00
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public boolean isOpaqueCube(IBlockState state){
|
2015-11-29 13:17:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-15 03:15:19 +01:00
|
|
|
@Override
|
2016-11-19 21:11:17 +01:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
|
|
|
|
ItemStack heldItem = player.getHeldItem(hand);
|
2016-01-08 13:31:58 +01:00
|
|
|
if(this.tryToggleRedstone(world, pos, player)){
|
2015-12-18 16:22:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-15 03:15:19 +01:00
|
|
|
if(!world.isRemote){
|
2016-01-07 21:41:28 +01:00
|
|
|
TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor)world.getTileEntity(pos);
|
2015-11-15 03:15:19 +01:00
|
|
|
if(reconstructor != null){
|
2016-11-16 16:59:00 +01:00
|
|
|
if(StackUtil.isValid(heldItem)){
|
2016-05-05 00:06:02 +02:00
|
|
|
Item item = heldItem.getItem();
|
2016-12-04 00:10:52 +01:00
|
|
|
if(item instanceof ILensItem && !StackUtil.isValid(reconstructor.slots.getStackInSlot(0))){
|
2015-12-21 22:18:33 +01:00
|
|
|
ItemStack toPut = heldItem.copy();
|
2016-11-16 16:59:00 +01:00
|
|
|
toPut = StackUtil.setStackSize(toPut, 1);
|
2016-12-04 00:10:52 +01:00
|
|
|
reconstructor.slots.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!
|
|
|
|
else if(item == Items.RECORD_11){
|
|
|
|
reconstructor.counter++;
|
|
|
|
reconstructor.markDirty();
|
|
|
|
}
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
|
|
|
else{
|
2016-12-04 00:10:52 +01:00
|
|
|
ItemStack slot = reconstructor.slots.getStackInSlot(0);
|
2016-11-16 16:59:00 +01:00
|
|
|
if(StackUtil.isValid(slot)){
|
2016-11-17 16:31:05 +01:00
|
|
|
player.setHeldItem(hand, slot.copy());
|
2016-12-04 00:10:52 +01:00
|
|
|
reconstructor.slots.setStackInSlot(0, StackUtil.getNull());
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
2015-11-22 18:52:11 +01:00
|
|
|
}
|
2015-11-15 03:15:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-22 20:23:54 +01:00
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public TileEntity createNewTileEntity(World world, int i){
|
2015-12-01 19:48:09 +01:00
|
|
|
return new TileEntityAtomicReconstructor();
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:28:57 +01:00
|
|
|
@Override
|
2015-12-22 07:28:27 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2016-07-25 22:37:14 +02:00
|
|
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
|
2016-11-26 21:32:27 +01:00
|
|
|
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
|
2015-12-21 22:28:57 +01:00
|
|
|
if(tile instanceof TileEntityAtomicReconstructor){
|
2016-12-04 00:10:52 +01:00
|
|
|
ItemStack slot = ((TileEntityAtomicReconstructor)tile).slots.getStackInSlot(0);
|
2015-12-21 22:28:57 +01:00
|
|
|
String strg;
|
2016-11-16 20:31:16 +01:00
|
|
|
if(!StackUtil.isValid(slot)){
|
2016-04-20 21:39:03 +02:00
|
|
|
strg = StringUtil.localize("info."+ModUtil.MOD_ID+".noLens");
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
strg = slot.getItem().getItemStackDisplayName(slot);
|
2015-12-21 23:53:01 +01:00
|
|
|
|
2016-07-21 17:38:46 +02:00
|
|
|
AssetUtil.renderStackToGui(slot, resolution.getScaledWidth()/2+15, resolution.getScaledHeight()/2-19, 1F);
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
2016-07-21 17:38:46 +02:00
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg, resolution.getScaledWidth()/2+35, resolution.getScaledHeight()/2-15, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:28:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 21:56:45 +01:00
|
|
|
|
|
|
|
@Override
|
2016-04-20 21:39:03 +02:00
|
|
|
protected ItemBlockBase getItemBlock(){
|
|
|
|
return new TheItemBlock(this);
|
2016-01-19 21:56:45 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.EPIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack){
|
2016-11-26 21:32:27 +01:00
|
|
|
int rotation = EnumFacing.getDirectionFromEntityLiving(pos, player).ordinal();
|
2016-07-04 20:15:41 +02:00
|
|
|
world.setBlockState(pos, this.getStateFromMeta(rotation), 2);
|
2016-02-01 17:49:55 +01:00
|
|
|
|
|
|
|
super.onBlockPlacedBy(world, pos, state, player, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-21 16:23:48 +01:00
|
|
|
public IBlockState getStateFromMeta(int meta){
|
|
|
|
return this.getDefaultState().withProperty(BlockDirectional.FACING, EnumFacing.getFront(meta));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state){
|
|
|
|
return state.getValue(BlockDirectional.FACING).getIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState(){
|
|
|
|
return new BlockStateContainer(this, BlockDirectional.FACING);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState withRotation(IBlockState state, Rotation rot){
|
|
|
|
return state.withProperty(BlockDirectional.FACING, rot.rotate(state.getValue(BlockDirectional.FACING)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState withMirror(IBlockState state, Mirror mirror){
|
|
|
|
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:56:45 +01:00
|
|
|
public static class TheItemBlock extends ItemBlockBase{
|
|
|
|
|
|
|
|
private long lastSysTime;
|
|
|
|
private int toPick1;
|
|
|
|
private int toPick2;
|
|
|
|
|
|
|
|
public TheItemBlock(Block block){
|
|
|
|
super(block);
|
|
|
|
this.setHasSubtypes(false);
|
|
|
|
this.setMaxDamage(0);
|
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2016-01-19 21:56:45 +01:00
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack stack){
|
|
|
|
return this.getUnlocalizedName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetadata(int damage){
|
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean bool){
|
2016-01-19 21:56:45 +01:00
|
|
|
long sysTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
if(this.lastSysTime+3000 < sysTime){
|
|
|
|
this.lastSysTime = sysTime;
|
2016-11-26 21:32:27 +01:00
|
|
|
this.toPick1 = player.world.rand.nextInt(NAME_FLAVOR_AMOUNTS_1)+1;
|
|
|
|
this.toPick2 = player.world.rand.nextInt(NAME_FLAVOR_AMOUNTS_2)+1;
|
2016-01-19 21:56:45 +01:00
|
|
|
}
|
|
|
|
|
2016-04-20 21:39:03 +02:00
|
|
|
String base = "tile."+ModUtil.MOD_ID+"."+((BlockAtomicReconstructor)this.block).getBaseName()+".info.";
|
2016-01-19 21:56:45 +01:00
|
|
|
list.add(StringUtil.localize(base+"1."+this.toPick1)+" "+StringUtil.localize(base+"2."+this.toPick2));
|
|
|
|
}
|
|
|
|
}
|
2015-11-14 21:27:36 +01:00
|
|
|
}
|