Reimplemented Atomic Deconstructor, Battery Box and Bio Reactor Blocks

This commit is contained in:
canitzp 2020-09-09 10:58:32 +02:00
parent a5c031c135
commit fb1663f106
12 changed files with 270 additions and 366 deletions

View file

@ -10,33 +10,35 @@ import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.client.MainWindow;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.Rarity;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.Mirror; import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation; import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List; import java.util.List;
@ -53,14 +55,11 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
} }
@Override @Override
public boolean isOpaqueCube(IBlockState state) { public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit){
return false;
}
@Override
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); ItemStack heldItem = player.getHeldItem(hand);
if (this.tryToggleRedstone(world, pos, player)) { return true; } if (this.tryToggleRedstone(world, pos, player)) {
return ActionResultType.SUCCESS;
}
if (!world.isRemote) { if (!world.isRemote) {
TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor) world.getTileEntity(pos); TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor) world.getTileEntity(pos);
if (reconstructor != null) { if (reconstructor != null) {
@ -73,7 +72,7 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
player.inventory.decrStackSize(player.inventory.currentItem, 1); player.inventory.decrStackSize(player.inventory.currentItem, 1);
} }
//Shush, don't tell anyone! //Shush, don't tell anyone!
else if (ConfigIntValues.ELEVEN.getValue() == 11 && item == Items.RECORD_11) { else if (ConfigIntValues.ELEVEN.getValue() == 11 && item == Items.MUSIC_DISC_11) {
reconstructor.counter++; reconstructor.counter++;
reconstructor.markDirty(); reconstructor.markDirty();
} }
@ -86,99 +85,84 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
} }
} }
} }
return true; return ActionResultType.SUCCESS;
} }
@Override @Override
public TileEntity createNewTileEntity(World world, int i) { public TileEntity createTileEntity(BlockState state, IBlockReader world){
return new TileEntityAtomicReconstructor(); return new TileEntityAtomicReconstructor();
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Dist.CLIENT)
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution) { public void displayHud(Minecraft minecraft, PlayerEntity player, ItemStack stack, BlockRayTraceResult posHit, MainWindow window) {
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos()); TileEntity tile = minecraft.world.getTileEntity(posHit.getPos());
if (tile instanceof TileEntityAtomicReconstructor) { if (tile instanceof TileEntityAtomicReconstructor) {
ItemStack slot = ((TileEntityAtomicReconstructor) tile).inv.getStackInSlot(0); ItemStack slot = ((TileEntityAtomicReconstructor) tile).inv.getStackInSlot(0);
String strg; ITextComponent displayString;
if (!StackUtil.isValid(slot)) { if (!StackUtil.isValid(slot)) {
strg = StringUtil.localize("info." + ActuallyAdditions.MODID + ".noLens"); displayString = new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".noLens");
} else { } else {
strg = slot.getItem().getItemStackDisplayName(slot); displayString = slot.getItem().getDisplayName(slot);
AssetUtil.renderStackToGui(slot, resolution.getScaledWidth() / 2 + 15, resolution.getScaledHeight() / 2 - 19, 1F); AssetUtil.renderStackToGui(slot, window.getScaledWidth() / 2 + 15, window.getScaledHeight() / 2 - 19, 1F);
} }
minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + strg, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 15, StringUtil.DECIMAL_COLOR_WHITE); minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + displayString.getFormattedText(), window.getScaledWidth() / 2 + 35, window.getScaledHeight() / 2 - 15, StringUtil.DECIMAL_COLOR_WHITE);
} }
} }
@Override @Override
protected BlockItemBase getItemBlock() { protected BlockItemBase getItemBlock() {
return new TheItemBlock(this); return new BlockItem();
} }
@Override @Override
public EnumRarity getRarity(ItemStack stack) { public Rarity getRarity(){
return EnumRarity.EPIC; return Rarity.EPIC;
} }
@Override @Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) { protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder){
int rotation = EnumFacing.getDirectionFromEntityLiving(pos, player).ordinal(); builder.add(BlockStateProperties.FACING);
world.setBlockState(pos, this.getStateFromMeta(rotation), 2);
super.onBlockPlacedBy(world, pos, state, player, stack);
} }
@Override @Override
public IBlockState getStateFromMeta(int meta) { public BlockState rotate(BlockState state, Rotation rot){
return this.getDefaultState().withProperty(BlockDirectional.FACING, EnumFacing.byIndex(meta)); return state.with(BlockStateProperties.FACING, rot.rotate(state.get(BlockStateProperties.FACING)));
} }
@Override @Override
public int getMetaFromState(IBlockState state) { public BlockState mirror(BlockState state, Mirror mirrorIn){
return state.getValue(BlockDirectional.FACING).getIndex(); return this.rotate(state, mirrorIn.toRotation(state.get(BlockStateProperties.FACING)));
} }
@Override @Override
protected BlockStateContainer createBlockState() { public boolean hasComparatorInputOverride(BlockState state){
return new BlockStateContainer(this, BlockDirectional.FACING); return true;
} }
@Override @Override
public IBlockState withRotation(IBlockState state, Rotation rot) { public int getComparatorInputOverride(BlockState blockState, World world, BlockPos pos) {
return state.withProperty(BlockDirectional.FACING, rot.rotate(state.getValue(BlockDirectional.FACING))); TileEntity t = world.getTileEntity(pos);
int i = 0;
if (t instanceof TileEntityAtomicReconstructor) {
i = ((TileEntityAtomicReconstructor) t).getEnergy();
}
return MathHelper.clamp(i / 20000, 0, 15);
} }
@Override public class BlockItem extends BlockItemBase {
public IBlockState withMirror(IBlockState state, Mirror mirror) {
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
}
public static class TheItemBlock extends BlockItemBase {
private long lastSysTime; private long lastSysTime;
private int toPick1; private int toPick1;
private int toPick2; private int toPick2;
public TheItemBlock(Block block) { public BlockItem() {
super(block); super(BlockAtomicReconstructor.this, new Properties());
this.setHasSubtypes(false);
this.setMaxDamage(0);
} }
@Override @Override
public String getTranslationKey(ItemStack stack) { public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag){
return this.getTranslationKey();
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag advanced) {
long sysTime = System.currentTimeMillis(); long sysTime = System.currentTimeMillis();
if (this.lastSysTime + 3000 < sysTime) { if (this.lastSysTime + 3000 < sysTime) {
@ -189,23 +173,9 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
} }
} }
String base = "tile." + ActuallyAdditions.MODID + "." + ((BlockAtomicReconstructor) this.block).getBaseName() + ".info."; String base = String.format("tile.%s.%s.info", ActuallyAdditions.MODID, BlockAtomicReconstructor.this.getRegistryName().getPath());
tooltip.add(StringUtil.localize(base + "1." + this.toPick1) + " " + StringUtil.localize(base + "2." + this.toPick2)); tooltip.add(new TranslationTextComponent(String.format("%s1.%s", base, this.toPick1)).appendSibling(new TranslationTextComponent(String.format("%s2.%s", base, this.toPick2))));
}
} }
@Override
public boolean hasComparatorInputOverride(IBlockState state) {
return true;
}
@Override
public int getComparatorInputOverride(IBlockState 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);
} }
} }

View file

@ -4,46 +4,49 @@ import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.items.ItemBattery; import de.ellpeck.actuallyadditions.mod.items.ItemBattery;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBatteryBox; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBatteryBox;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable; // todo add rarity RARE
public class BlockBatteryBox extends BlockContainerBase { public class BlockBatteryBox extends BlockContainerBase {
public static final VoxelShape SHAPE = Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D);
public BlockBatteryBox() { public BlockBatteryBox() {
super(Properties.create(Material.ROCK) super(Properties.create(Material.ROCK)
.hardnessAndResistance(1.5f, 10.0f) .hardnessAndResistance(1.5f, 10.0f)
.harvestLevel(0) .harvestLevel(0)
.harvestTool(ToolType.PICKAXE) .harvestTool(ToolType.PICKAXE)
.sound(SoundType.STONE)); .sound(SoundType.STONE));
// this.setHarvestLevel("pickaxe", 0);
// this.setHardness(1.5F);
// this.setResistance(10.0F);
// this.setSoundType(SoundType.STONE);
} }
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public Rarity getRarity(){
return BlockSlabs.AABB_BOTTOM_HALF; return Rarity.RARE;
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context){
return SHAPE;
}
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit){
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityBatteryBox) { if (tile instanceof TileEntityBatteryBox) {
TileEntityBatteryBox box = (TileEntityBatteryBox) tile; TileEntityBatteryBox box = (TileEntityBatteryBox) tile;
@ -53,33 +56,23 @@ public class BlockBatteryBox extends BlockContainerBase {
if (stack.getItem() instanceof ItemBattery && !StackUtil.isValid(box.inv.getStackInSlot(0))) { if (stack.getItem() instanceof ItemBattery && !StackUtil.isValid(box.inv.getStackInSlot(0))) {
box.inv.setStackInSlot(0, stack.copy()); box.inv.setStackInSlot(0, stack.copy());
player.setHeldItem(hand, StackUtil.getEmpty()); player.setHeldItem(hand, StackUtil.getEmpty());
return true; return ActionResultType.SUCCESS;
} }
} else { } else {
ItemStack inSlot = box.inv.getStackInSlot(0); ItemStack inSlot = box.inv.getStackInSlot(0);
if (StackUtil.isValid(inSlot)) { if (StackUtil.isValid(inSlot)) {
player.setHeldItem(hand, inSlot.copy()); player.setHeldItem(hand, inSlot.copy());
box.inv.setStackInSlot(0, StackUtil.getEmpty()); box.inv.setStackInSlot(0, StackUtil.getEmpty());
return true; return ActionResultType.SUCCESS;
} }
} }
} }
return false; return super.onBlockActivated(state, world, pos, player, hand, hit);
} }
@Override @Override
public boolean isOpaqueCube(IBlockState state) { public TileEntity createTileEntity(BlockState state, IBlockReader world){
return false;
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.RARE;
}
@Nullable
@Override
public TileEntity createNewTileEntity(IBlockReader worldIn) {
return new TileEntityBatteryBox(); return new TileEntityBatteryBox();
} }
} }

View file

@ -1,19 +1,18 @@
package de.ellpeck.actuallyadditions.mod.blocks; package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Rarity;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
@ -27,22 +26,22 @@ public class BlockBioReactor extends BlockContainerBase {
} }
@Override @Override
public TileEntity createNewTileEntity(World worldIn, int meta) { public TileEntity createTileEntity(BlockState state, IBlockReader world){
return new TileEntityBioReactor(); return new TileEntityBioReactor();
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9) { public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit){
if (!world.isRemote) { if (!world.isRemote) {
if (world.getTileEntity(pos) instanceof TileEntityBioReactor) { if (world.getTileEntity(pos) instanceof TileEntityBioReactor) {
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.BIO_REACTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); // todo open gui: player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.BIO_REACTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
} }
} }
return true; return ActionResultType.SUCCESS;
} }
@Override @Override
public EnumRarity getRarity(ItemStack stack) { public Rarity getRarity() {
return EnumRarity.EPIC; return Rarity.EPIC;
} }
} }

View file

@ -18,6 +18,7 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@ -25,7 +26,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockSlabs extends Block { public class BlockSlabs extends Block {
public static final AxisAlignedBB AABB_BOTTOM_HALF = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D); public static final VoxelShape AABB_BOTTOM_HALF = Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D);
private static final AxisAlignedBB AABB_TOP_HALF = new AxisAlignedBB(0.0D, 0.5D, 0.0D, 1.0D, 1.0D, 1.0D); private static final AxisAlignedBB AABB_TOP_HALF = new AxisAlignedBB(0.0D, 0.5D, 0.0D, 1.0D, 1.0D, 1.0D);
private final BlockState fullBlockState; private final BlockState fullBlockState;

View file

@ -1,16 +1,16 @@
package de.ellpeck.actuallyadditions.mod.blocks; package de.ellpeck.actuallyadditions.mod.blocks;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.api.distmarker.OnlyIn;
public interface IHudDisplay { public interface IHudDisplay {
@SideOnly(Side.CLIENT) @OnlyIn(Dist.CLIENT)
void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution); void displayHud(Minecraft minecraft, PlayerEntity player, ItemStack stack, BlockRayTraceResult posHit, MainWindow window);
} }

View file

@ -1,42 +1,17 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; package de.ellpeck.actuallyadditions.mod.blocks.base;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item;
public class BlockBase extends Block { public class BlockBase extends Block implements IBaseBlock{
private final String name; public BlockBase(Properties properties) {
public BlockBase(Properties properties, String name) {
super(properties); super(properties);
this.name = name;
this.register();
}
@Deprecated
private void register() {
//ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
}
protected String getBaseName() {
return this.name;
}
protected BlockItemBase getItemBlock() {
return new BlockItemBase(this);
}
public boolean shouldAddCreative() {
return true;
}
/*@Override
public void registerRendering() {
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
} }
@Override @Override
public Rarity getRarity(ItemStack stack) { public BlockItemBase getItemBlock() {
return EnumRarity.COMMON; return new BlockItemBase(this, new Item.Properties());
}*/ }
} }

View file

@ -2,32 +2,17 @@ package de.ellpeck.actuallyadditions.mod.blocks.base;
import net.minecraft.block.BushBlock; import net.minecraft.block.BushBlock;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.item.Item;
public class BlockBushBase extends BushBlock implements IBaseBlock {
public class BlockBushBase extends BushBlock {
public BlockBushBase(Properties properties) { public BlockBushBase(Properties properties) {
super(properties.sound(SoundType.PLANT)); super(properties.sound(SoundType.PLANT));
// this.register();
} }
// private void register() { @Override
// ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); public BlockItemBase getItemBlock(){
// } return new BlockItemBase(this, new Item.Properties());
// protected ItemBlockBase getItemBlock() {
// return new ItemBlockBase(this);
// }
public boolean shouldAddCreative() {
return true;
} }
// @Override
// public void registerRendering() {
// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
// }
// @Override
// public EnumRarity getRarity(ItemStack stack) {
// return EnumRarity.COMMON;
// }
} }

View file

@ -29,36 +29,13 @@ import net.minecraftforge.fluids.capability.templates.FluidTank;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Random; import java.util.Random;
public abstract class BlockContainerBase extends Block { public abstract class BlockContainerBase extends BlockBase {
public BlockContainerBase(Properties properties) { public BlockContainerBase(Properties properties) {
super(properties); super(properties);
// this.register();
} }
// private void register() {
// ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
// }
// protected ItemBlockBase getItemBlock() {
// return new ItemBlockBase(this);
// }
public boolean shouldAddCreative() {
return true;
}
// @Override
// public void registerRendering() {
// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
// }
//
// @Override
// public EnumRarity getRarity(ItemStack stack) {
// return EnumRarity.COMMON;
// }
private void dropInventory(World world, BlockPos position) { private void dropInventory(World world, BlockPos position) {
if (!world.isRemote) { if (!world.isRemote) {
TileEntity aTile = world.getTileEntity(position); TileEntity aTile = world.getTileEntity(position);

View file

@ -2,12 +2,12 @@ package de.ellpeck.actuallyadditions.mod.blocks.base;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
public class BlockItemBase extends BlockItem { public class BlockItemBase extends BlockItem {
public BlockItemBase(Block block) { public <T extends Block & IBaseBlock> BlockItemBase(T block , Item.Properties properties) {
super(block, new Properties()); super(block, properties.rarity(block.getRarity()));
this.setRegistryName(block.getRegistryName());
} }
} }

View file

@ -30,9 +30,8 @@ import net.minecraftforge.items.ItemHandlerHelper;
import java.util.List; import java.util.List;
public class BlockPlant extends CropsBlock {// implements ItemBlockBase.ICustomRarity, IHasModel { public class BlockPlant extends CropsBlock implements IBaseBlock {
// private final String name;
private final int minDropAmount; private final int minDropAmount;
private final int addDropAmount; private final int addDropAmount;
public Item seedItem; public Item seedItem;
@ -42,10 +41,9 @@ public class BlockPlant extends CropsBlock {// implements ItemBlockBase.ICustomR
// todo: find the correct properties for crops // todo: find the correct properties for crops
public BlockPlant(int minDropAmount, int addDropAmount) { public BlockPlant(int minDropAmount, int addDropAmount) {
super(Properties.create(Material.PLANTS)); super(Properties.create(Material.PLANTS));
// this.name = name;
this.minDropAmount = minDropAmount; this.minDropAmount = minDropAmount;
this.addDropAmount = addDropAmount; this.addDropAmount = addDropAmount;
// this.register();
} }
// todo: check what this is doing // todo: check what this is doing
@ -55,39 +53,24 @@ public class BlockPlant extends CropsBlock {// implements ItemBlockBase.ICustomR
this.returnMeta = returnMeta; this.returnMeta = returnMeta;
} }
// private void register() { @Override
// ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); public BlockItemBase getItemBlock(){
// } return new BlockItemBase(this, new Item.Properties());
}
// protected String getBaseName() {
// return this.name;
// }
// protected ItemBlockBase getItemBlock() {
// return new ItemBlockBase(this);
// }
public boolean shouldAddCreative() { public boolean shouldAddCreative() {
return false; return false;
} }
// @Override
// public void registerRendering() {
// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
// }
//
@Override @Override
public PlantType getPlantType(IBlockReader world, BlockPos pos) { public PlantType getPlantType(IBlockReader world, BlockPos pos) {
return PlantType.Crop; return PlantType.Crop;
} }
//
// @Override
// public int damageDropped(IBlockState state) {
// return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
// }
@Override
protected IItemProvider getSeedsItem() {
return this.seedItem;
}
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
@ -117,26 +100,26 @@ public class BlockPlant extends CropsBlock {// implements ItemBlockBase.ICustomR
return super.onBlockActivated(state, world, pos, player, handIn, hit); return super.onBlockActivated(state, world, pos, player, handIn, hit);
} }
/* todo: this is likely handled by loot tables now
@Override @Override
protected IItemProvider getSeedsItem() { public int damageDropped(IBlockState state) {
return this.seedItem; return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
} }
// todo: this is likely handled by loot tables now @Override
public int quantityDropped(IBlockState state, int fortune, Random random) {
return this.getMetaFromState(state) >= 7 ? random.nextInt(this.addDropAmount) + this.minDropAmount : super.quantityDropped(state, fortune, random);
}
// @Override @Override
// public int quantityDropped(IBlockState state, int fortune, Random random) { public Item getCrop() {
// return this.getMetaFromState(state) >= 7 ? random.nextInt(this.addDropAmount) + this.minDropAmount : super.quantityDropped(state, fortune, random); return this.returnItem;
// } }
// @Override @Override
// public Item getCrop() { public Item getItemDropped(IBlockState state, Random rand, int par3) {
// return this.returnItem; return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
// } }
*/
// @Override
// public Item getItemDropped(IBlockState state, Random rand, int par3) {
// return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
// }
} }

View file

@ -0,0 +1,17 @@
package de.ellpeck.actuallyadditions.mod.blocks.base;
import net.minecraft.item.Rarity;
public interface IBaseBlock {
BlockItemBase getItemBlock();
default boolean shouldAddCreative() {
return true;
}
default Rarity getRarity() {
return Rarity.COMMON;
}
}

View file

@ -2,6 +2,7 @@ package de.ellpeck.actuallyadditions.mod.event;
import java.util.Locale; import java.util.Locale;
import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay; import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
@ -17,28 +18,26 @@ import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword; import net.minecraft.item.SwordItem;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
@SideOnly(Side.CLIENT) @OnlyIn(Dist.CLIENT)
public class ClientEvents { public class ClientEvents {
private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY + " "; private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY + " ";
@ -51,9 +50,9 @@ public class ClientEvents {
} }
@SubscribeEvent @SubscribeEvent
public void onClientTick(ClientTickEvent event) { public void onClientTick(TickEvent.ClientTickEvent event) {
if (event.phase == Phase.END) { if (event.phase == TickEvent.Phase.END) {
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getInstance();
if (mc.world == null) { if (mc.world == null) {
WorldData.clear(); WorldData.clear();
@ -77,7 +76,7 @@ public class ClientEvents {
} }
} }
if (ItemWingsOfTheBats.THE_BAT_BAT.equalsIgnoreCase(stack.getDisplayName()) && stack.getItem() instanceof ItemSword) { if (ItemWingsOfTheBats.THE_BAT_BAT.equalsIgnoreCase(stack.getDisplayName()) && stack.getItem() instanceof SwordItem) {
event.getToolTip().set(0, TextFormatting.GOLD + event.getToolTip().get(0)); event.getToolTip().set(0, TextFormatting.GOLD + event.getToolTip().get(0));
event.getToolTip().add(1, TextFormatting.RED.toString() + TextFormatting.ITALIC + "That's a really bat pun"); event.getToolTip().add(1, TextFormatting.RED.toString() + TextFormatting.ITALIC + "That's a really bat pun");
} }
@ -86,7 +85,7 @@ public class ClientEvents {
//Advanced Item Info //Advanced Item Info
if (event.getFlags().isAdvanced() && StackUtil.isValid(event.getItemStack())) { if (event.getFlags().isAdvanced() && StackUtil.isValid(event.getItemStack())) {
if (ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()) { if (ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()) {
if (GuiScreen.isCtrlKeyDown()) { if (Screen.hasControlDown()) {
event.getToolTip().add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".extraInfo.desc") + ":"); event.getToolTip().add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".extraInfo.desc") + ":");
//OreDict Names //OreDict Names
@ -125,10 +124,10 @@ public class ClientEvents {
} }
//NBT //NBT
NBTTagCompound compound = event.getItemStack().getTagCompound(); CompoundNBT compound = event.getItemStack().getTag();
if (compound != null && !compound.isEmpty()) { if (compound != null && !compound.isEmpty()) {
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".nbt.desc") + ":"); event.getToolTip().add(ADVANCED_INFO_HEADER_PRE + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".nbt.desc") + ":");
if (GuiScreen.isShiftKeyDown()) { if (Screen.hasShiftDown()) {
int limit = ConfigIntValues.CTRL_INFO_NBT_CHAR_LIMIT.getValue(); int limit = ConfigIntValues.CTRL_INFO_NBT_CHAR_LIMIT.getValue();
String compoundStrg = compound.toString(); String compoundStrg = compound.toString();
int compoundStrgLength = compoundStrg.length(); int compoundStrgLength = compoundStrg.length();
@ -159,32 +158,34 @@ public class ClientEvents {
@SubscribeEvent @SubscribeEvent
public void onGameOverlay(RenderGameOverlayEvent.Post event) { public void onGameOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null) { if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getInstance().currentScreen == null) {
Minecraft minecraft = Minecraft.getMinecraft(); Minecraft minecraft = Minecraft.getInstance();
EntityPlayer player = minecraft.player; PlayerEntity player = minecraft.player;
RayTraceResult posHit = minecraft.objectMouseOver; RayTraceResult posHit = minecraft.objectMouseOver;
FontRenderer font = minecraft.fontRenderer; FontRenderer font = minecraft.fontRenderer;
ItemStack stack = player.getHeldItemMainhand(); ItemStack stack = player.getHeldItemMainhand();
if(posHit instanceof BlockRayTraceResult){
BlockRayTraceResult blockRayTraceResult = ((BlockRayTraceResult) posHit);
if (StackUtil.isValid(stack)) { if (StackUtil.isValid(stack)) {
if (stack.getItem() instanceof IHudDisplay) { if (stack.getItem() instanceof IHudDisplay) {
((IHudDisplay) stack.getItem()).displayHud(minecraft, player, stack, posHit, event.getResolution()); ((IHudDisplay) stack.getItem()).displayHud(minecraft, player, stack, blockRayTraceResult, event.getWindow());
} }
} }
if (posHit != null && posHit.getBlockPos() != null) { if (blockRayTraceResult.getPos() != null) {
Block blockHit = minecraft.world.getBlockState(posHit.getBlockPos()).getBlock(); Block blockHit = minecraft.world.getBlockState(blockRayTraceResult.getPos()).getBlock();
TileEntity tileHit = minecraft.world.getTileEntity(posHit.getBlockPos()); TileEntity tileHit = minecraft.world.getTileEntity(blockRayTraceResult.getPos());
if (blockHit instanceof IHudDisplay) { if (blockHit instanceof IHudDisplay) {
((IHudDisplay) blockHit).displayHud(minecraft, player, stack, posHit, event.getResolution()); ((IHudDisplay) blockHit).displayHud(minecraft, player, stack, blockRayTraceResult, event.getWindow());
} }
if (tileHit instanceof TileEntityBase) { if (tileHit instanceof TileEntityBase) {
TileEntityBase base = (TileEntityBase) tileHit; TileEntityBase base = (TileEntityBase) tileHit;
if (base.isRedstoneToggle()) { if (base.isRedstoneToggle()) {
String strg = String.format("%s: %s", StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode.name"), TextFormatting.DARK_RED + StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode." + (base.isPulseMode ? "pulse" : "deactivation")) + TextFormatting.RESET); String strg = String.format("%s: %s", StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode.name"), TextFormatting.DARK_RED + StringUtil.localize("info." + ActuallyAdditions.MODID + ".redstoneMode." + (base.isPulseMode ? "pulse" : "deactivation")) + TextFormatting.RESET);
font.drawStringWithShadow(strg, event.getResolution().getScaledWidth() / 2 + 5, event.getResolution().getScaledHeight() / 2 + 5, StringUtil.DECIMAL_COLOR_WHITE); font.drawStringWithShadow(strg, event.getWindow().getScaledWidth() / 2 + 5, event.getWindow().getScaledHeight() / 2 + 5, StringUtil.DECIMAL_COLOR_WHITE);
String expl; String expl;
if (StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator) { if (StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator) {
@ -192,7 +193,7 @@ public class ClientEvents {
} else { } else {
expl = TextFormatting.GRAY.toString() + TextFormatting.ITALIC + StringUtil.localizeFormatted("info." + ActuallyAdditions.MODID + ".redstoneMode.invalidItem", StringUtil.localize(ConfigValues.itemRedstoneTorchConfigurator.getTranslationKey() + ".name")); expl = TextFormatting.GRAY.toString() + TextFormatting.ITALIC + StringUtil.localizeFormatted("info." + ActuallyAdditions.MODID + ".redstoneMode.invalidItem", StringUtil.localize(ConfigValues.itemRedstoneTorchConfigurator.getTranslationKey() + ".name"));
} }
font.drawStringWithShadow(expl, event.getResolution().getScaledWidth() / 2 + 5, event.getResolution().getScaledHeight() / 2 + 15, StringUtil.DECIMAL_COLOR_WHITE); font.drawStringWithShadow(expl, event.getWindow().getScaledWidth() / 2 + 5, event.getWindow().getScaledHeight() / 2 + 15, StringUtil.DECIMAL_COLOR_WHITE);
} }
} }
@ -202,16 +203,19 @@ public class ClientEvents {
if (energyDisplay == null) { if (energyDisplay == null) {
energyDisplay = new EnergyDisplay(0, 0, null); energyDisplay = new EnergyDisplay(0, 0, null);
} }
energyDisplay.setData(2, event.getResolution().getScaledHeight() - 96, display.getEnergyStorage(), true, true); energyDisplay.setData(2, event.getWindow().getScaledHeight() - 96, display.getEnergyStorage(), true, true);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.color(1F, 1F, 1F, 1F); GlStateManager.color4f(1F, 1F, 1F, 1F);
energyDisplay.draw(); energyDisplay.draw();
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
} }
} }
} }
}
} }
} }