Refactored ItemBlock naming

This commit is contained in:
Unknown 2018-07-24 14:18:54 +02:00 committed by unknown
parent 60fa2c0c98
commit 948ae4429f
14 changed files with 19 additions and 93 deletions

View file

@ -47,7 +47,7 @@ public abstract class BlockAbstractBase extends Block implements IBlockBase {
@Nullable
@Override
public ItemBlock createItemBlock() {
return new ItemBlockAbstractBase(this);
return new ItemBlockAbstractBase(this, false, true);
}
@SideOnly(Side.CLIENT)

View file

@ -69,7 +69,7 @@ public abstract class BlockAbstractContainer extends BlockContainer implements I
@Nullable
@Override
public ItemBlock createItemBlock() {
return new ItemBlockAbstractBase(this);
return new ItemBlockAbstractBase(this, false, true);
}
@SideOnly(Side.CLIENT)

View file

@ -35,12 +35,16 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockAbstractBase extends ItemBlock implements IItemBase {
final boolean hasUniqueName;
// warning: ItemBlock is created during registration, while block is still being constructed.
// As such, we can't use block properties from constructor
public ItemBlockAbstractBase(final Block block) {
public ItemBlockAbstractBase(final Block block, final boolean hasSubtypes, final boolean hasUniqueName) {
super(block);
setHasSubtypes(hasSubtypes);
setUnlocalizedName(block.getUnlocalizedName());
this.hasUniqueName = hasUniqueName;
}
@Override
@ -51,7 +55,8 @@ public class ItemBlockAbstractBase extends ItemBlock implements IItemBase {
@Nonnull
@Override
public String getUnlocalizedName(final ItemStack itemStack) {
if ( itemStack == null
if ( hasUniqueName
|| itemStack == null
|| !(block instanceof BlockAbstractContainer)
|| !((BlockAbstractContainer) block).hasSubBlocks ) {
return getUnlocalizedName();

View file

@ -1,40 +0,0 @@
package cr0s.warpdrive.block.breathing;
import cr0s.warpdrive.block.ItemBlockAbstractBase;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
public class ItemBlockAirShield extends ItemBlockAbstractBase {
public ItemBlockAirShield(final Block block) {
super(block);
setHasSubtypes(true);
}
@Override
public int getMetadata(final int damage) {
return damage;
}
@Override
public void getSubItems(@Nonnull final CreativeTabs creativeTab, @Nonnull final NonNullList<ItemStack> list) {
if (!isInCreativeTab(creativeTab)) {
return;
}
for (int metadata = 0; metadata < 16; metadata++) {
list.add(new ItemStack(this, 1, metadata));
}
}
@Nonnull
@Override
public String getUnlocalizedName(final ItemStack itemstack) {
return getUnlocalizedName();
}
}

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.block.decoration;
import cr0s.warpdrive.block.BlockAbstractBase;
import cr0s.warpdrive.block.ItemBlockAbstractBase;
import cr0s.warpdrive.data.CelestialObjectManager;
import cr0s.warpdrive.data.EnumGasColor;
import cr0s.warpdrive.data.EnumTier;
@ -66,7 +67,7 @@ public class BlockGas extends BlockAbstractBase {
@Nullable
@Override
public ItemBlock createItemBlock() {
return new ItemBlockGas(this);
return new ItemBlockAbstractBase(this, true, false);
}
@Override

View file

@ -10,9 +10,7 @@ import javax.annotation.Nonnull;
public class ItemBlockDecorative extends ItemBlockAbstractBase {
public ItemBlockDecorative(final Block block) {
super(block);
setHasSubtypes(true);
super(block, true, false);
}
@Nonnull

View file

@ -1,13 +0,0 @@
package cr0s.warpdrive.block.decoration;
import cr0s.warpdrive.block.ItemBlockAbstractBase;
import net.minecraft.block.Block;
public class ItemBlockGas extends ItemBlockAbstractBase {
public ItemBlockGas(final Block block) {
super(block);
setHasSubtypes(true);
}
}

View file

@ -15,10 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockCapacitor extends ItemBlockAbstractBase {
ItemBlockCapacitor(final Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(true);
super(block, true, false);
}
@Nonnull

View file

@ -3,6 +3,7 @@ package cr0s.warpdrive.block.forcefield;
import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IDamageReceiver;
import cr0s.warpdrive.block.ItemBlockAbstractBase;
import cr0s.warpdrive.block.hull.BlockHullGlass;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
@ -143,7 +144,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
@Nullable
@Override
public ItemBlock createItemBlock() {
return new ItemBlockForceField(this);
return new ItemBlockAbstractBase(this, true, true);
}
@Override

View file

@ -1,14 +0,0 @@
package cr0s.warpdrive.block.forcefield;
import cr0s.warpdrive.block.ItemBlockAbstractBase;
import net.minecraft.block.Block;
public class ItemBlockForceField extends ItemBlockAbstractBase {
public ItemBlockForceField(final Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(true);
}
}

View file

@ -15,10 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockForceFieldProjector extends ItemBlockAbstractBase {
public ItemBlockForceFieldProjector(final Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(true);
super(block, true, false);
}
@Nonnull

View file

@ -7,9 +7,6 @@ import net.minecraft.block.Block;
public class ItemBlockForceFieldRelay extends ItemBlockAbstractBase {
public ItemBlockForceFieldRelay(final Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(false);
super(block, true, false);
}
}

View file

@ -15,10 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockHull extends ItemBlockAbstractBase {
ItemBlockHull(final Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(true);
super(block, true, false);
}
@Nonnull

View file

@ -30,7 +30,7 @@ import java.util.UUID;
public class ItemBlockTransporterBeacon extends ItemBlockAbstractBase implements IItemTransporterBeacon {
public ItemBlockTransporterBeacon(final Block block) {
super(block);
super(block, false, false);
setMaxStackSize(1);
setMaxDamage(100 * 8);