Migrated batteries + TR Itemgroup

This commit is contained in:
drcrazy 2019-02-22 00:22:43 +03:00
parent 0c99a94250
commit e513e20e5a
16 changed files with 101 additions and 108 deletions

View file

@ -26,10 +26,13 @@ package techreborn;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.FluidRegistry;
@ -83,13 +86,14 @@ public class TechReborn {
public static TechReborn INSTANCE;
public static TechRebornWorldGen worldGen;
public static File configDir;
public static final ItemGroup ITEMGROUP = new ItemGroup(-1, MOD_ID) {
@OnlyIn(Dist.CLIENT)
public ItemStack createIcon() {
return TRContent.Parts.MACHINE_PARTS.getStack();
}
};
// public static final CreativeTabs TAB = new CreativeTabs(MOD_ID) {
// @Override
// public ItemStack createIcon() {
// return TRContent.Parts.MACHINE_PARTS.getStack();
// }
// };
public TechReborn() {
MinecraftForge.EVENT_BUS.register(this);

View file

@ -31,6 +31,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import techreborn.world.RubberTreeGenerator;
@ -47,8 +48,8 @@ public class BlockRubberSapling extends BlockSapling {
}
@Override
public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand) {
if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) {
public void grow(IWorld worldIn, BlockPos pos, IBlockState state, Random rand) {
if (!net.minecraftforge.event.ForgeEventFactory.saplingGrowTree(worldIn, rand, pos)) {
return;
}
worldIn.setBlockToAir(pos);

View file

@ -38,8 +38,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.api.ToolManager;
@ -55,7 +55,7 @@ public class BlockLamp extends BaseTileBlock {
public static DirectionProperty FACING;
public static BooleanProperty ACTIVE;
private AxisAlignedBB[] bbs;
protected final VoxelShape[] shape;
private int cost;
private int brightness;
@ -63,23 +63,23 @@ public class BlockLamp extends BaseTileBlock {
public BlockLamp(int brightness, int cost, double depth, double width) {
super(Block.Properties.create(Material.REDSTONE_LIGHT));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, EnumFacing.NORTH).with(ACTIVE, false));
this.bbs = GenBoundingBoxes(depth, width);
this.shape = GenCuboidShapes(depth, width);
this.cost = cost;
this.brightness = brightness;
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/lighting"));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
private static AxisAlignedBB[] GenBoundingBoxes(double depth, double width) {
AxisAlignedBB[] bb = {
new AxisAlignedBB(width, 1.0 - depth, width, 1.0 - width, 1.0D, 1.0 - width),
new AxisAlignedBB(width, 0.0D, width, 1.0 - width, depth, 1.0 - width),
new AxisAlignedBB(width, width, 1.0 - depth, 1.0 - width, 1.0 - width, 1.0D),
new AxisAlignedBB(width, width, 0.0D, 1.0 - width, 1.0 - width, depth),
new AxisAlignedBB(1.0 - depth, width, width, 1.0D, 1.0 - width, 1.0 - width),
new AxisAlignedBB(0.0D, width, width, depth, 1.0 - width, 1.0 - width),
};
return bb;
private VoxelShape[] GenCuboidShapes(double depth, double width) {
VoxelShape[] shapes = {
Block.makeCuboidShape(width, 1.0 - depth, width, 1.0 - width, 1.0D, 1.0 - width),
Block.makeCuboidShape(width, 0.0D, width, 1.0 - width, depth, 1.0 - width),
Block.makeCuboidShape(width, width, 1.0 - depth, 1.0 - width, 1.0 - width, 1.0D),
Block.makeCuboidShape(width, width, 0.0D, 1.0 - width, 1.0 - width, depth),
Block.makeCuboidShape(1.0 - depth, width, width, 1.0D, 1.0 - width, 1.0 - width),
Block.makeCuboidShape(0.0D, width, width, depth, 1.0 - width, 1.0 - width),
};
return shapes;
}
public static boolean isActive(IBlockState state) {
@ -147,10 +147,10 @@ public class BlockLamp extends BaseTileBlock {
else
return BlockFaceShape.UNDEFINED;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockReader worldIn, BlockPos pos) {
return this.bbs[getFacing(state).getIndex()];
public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos) {
return shape[getFacing(state).getIndex()];
}
@SuppressWarnings("deprecation")

View file

@ -97,24 +97,24 @@ public class RegistryEventHandler {
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
Arrays.stream(Ores.values()).forEach(value -> RebornRegistry.registerBlock(value.block));
Arrays.stream(StorageBlocks.values()).forEach(value -> RebornRegistry.registerBlock(value.block));
Arrays.stream(Ores.values()).forEach(value -> RebornRegistry.registerBlock(value.block, new Item.Properties()));
Arrays.stream(StorageBlocks.values()).forEach(value -> RebornRegistry.registerBlock(value.block, new Item.Properties()));
Arrays.stream(MachineBlocks.values()).forEach(value -> {
RebornRegistry.registerBlock(value.frame);
RebornRegistry.registerBlock(value.casing);
RebornRegistry.registerBlock(value.frame, new Item.Properties());
RebornRegistry.registerBlock(value.casing, new Item.Properties());
});
Arrays.stream(SolarPanels.values()).forEach(value -> RebornRegistry.registerBlock(value.block));
Arrays.stream(Cables.values()).forEach(value -> RebornRegistry.registerBlock(value.block));
Arrays.stream(Machine.values()).forEach(value -> RebornRegistry.registerBlock(value.block));
Arrays.stream(SolarPanels.values()).forEach(value -> RebornRegistry.registerBlock(value.block, new Item.Properties()));
Arrays.stream(Cables.values()).forEach(value -> RebornRegistry.registerBlock(value.block, new Item.Properties()));
Arrays.stream(Machine.values()).forEach(value -> RebornRegistry.registerBlock(value.block, new Item.Properties()));
// Misc. blocks
RebornRegistry.registerBlock(TRContent.COMPUTER_CUBE = InitUtils.setup(new BlockComputerCube(), "computer_cube"));
RebornRegistry.registerBlock(TRContent.NUKE = InitUtils.setup(new BlockNuke(), "nuke"));
RebornRegistry.registerBlock(TRContent.REFINED_IRON_FENCE = InitUtils.setup(new BlockRefinedIronFence(), "refined_iron_fence"));
RebornRegistry.registerBlock(TRContent.REINFORCED_GLASS = InitUtils.setup(new BlockReinforcedGlass(), "reinforced_glass"));
RebornRegistry.registerBlock(TRContent.RUBBER_LEAVES = InitUtils.setup(new BlockRubberLeaves(), "rubber_leaves"));
RebornRegistry.registerBlock(TRContent.RUBBER_LOG = InitUtils.setup(new BlockRubberLog(), "rubber_log"));
RebornRegistry.registerBlock(TRContent.RUBBER_PLANKS = InitUtils.setup(new BlockRubberPlank(), "rubber_planks"));
RebornRegistry.registerBlock(TRContent.COMPUTER_CUBE = InitUtils.setup(new BlockComputerCube(), "computer_cube"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.NUKE = InitUtils.setup(new BlockNuke(), "nuke"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.REFINED_IRON_FENCE = InitUtils.setup(new BlockRefinedIronFence(), "refined_iron_fence"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.REINFORCED_GLASS = InitUtils.setup(new BlockReinforcedGlass(), "reinforced_glass"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.RUBBER_LEAVES = InitUtils.setup(new BlockRubberLeaves(), "rubber_leaves"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.RUBBER_LOG = InitUtils.setup(new BlockRubberLog(), "rubber_log"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.RUBBER_PLANKS = InitUtils.setup(new BlockRubberPlank(), "rubber_planks"), new Item.Properties());
RebornRegistry.registerBlock(TRContent.RUBBER_SAPLING = InitUtils.setup(new BlockRubberSapling(), "rubber_sapling"),
ItemBlockRubberSapling.class,
"rubber_sapling");
@ -123,7 +123,7 @@ public class RegistryEventHandler {
new ItemSlab(TRContent.RUBBER_LOG_SLAB_HALF, (BlockSlab) TRContent.RUBBER_LOG_SLAB_HALF, (BlockSlab) TRContent.RUBBER_LOG_SLAB_DOUBLE),
"rubber_plank_double_slab");
RebornRegistry.registerBlock(TRContent.RUBBER_LOG_STAIR = InitUtils.setup(new BlockRubberPlankStair(TRContent.RUBBER_LOG.getDefaultState(), "rubber_plank"),
"rubber_plank_stair"));
"rubber_plank_stair"), new Item.Properties());
TechReborn.LOGGER.debug("TechReborns Blocks Loaded");
}

View file

@ -392,7 +392,7 @@ public class TRContent {
private Dusts() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name + "_dust");
}
@ -423,7 +423,7 @@ public class TRContent {
private SmallDusts() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name + "_small_dust");
}
@ -449,7 +449,7 @@ public class TRContent {
private Gems() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name + "_gem");
}
@ -476,7 +476,7 @@ public class TRContent {
private Ingots() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name + "_ingot");
}
@ -503,7 +503,7 @@ public class TRContent {
private Nuggets() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name + "_nugget");
}
@ -570,7 +570,7 @@ public class TRContent {
private Parts() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name);
}
@ -599,7 +599,7 @@ public class TRContent {
private Plates() {
name = this.toString().toLowerCase();
item = new Item();
item = new Item(new Item.Properties().group(TechReborn.ITEMGROUP));
InitUtils.setup(item, name + "_plate");
}

View file

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import reborncore.api.tile.IUpgrade;
import reborncore.common.recipes.IUpgradeHandler;
import reborncore.common.tile.TileMachineBase;
import techreborn.TechReborn;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -39,9 +40,9 @@ public class ItemUpgrade extends Item implements IUpgrade {
public final IUpgrade behavior;
public ItemUpgrade(String name, IUpgrade process) {
super(new Item.Properties().group(TechReborn.ITEMGROUP).maxStackSize(16));
this.name = name;
this.behavior = process;
setMaxStackSize(16);
}
@Override

View file

@ -52,9 +52,7 @@ public class ItemLapotronicOrbpack extends ItemArmor implements IEnergyItemInfo
public int transferLimit = 100_000;
public ItemLapotronicOrbpack() {
super(ArmorMaterial.DIAMOND, EntityEquipmentSlot.CHEST, (new Item.Builder()).group(ItemGroup.COMBAT));
//TODO: move to builder
//setMaxStackSize(1);
super(ArmorMaterial.DIAMOND, EntityEquipmentSlot.CHEST, new Item.Properties().maxStackSize(1));
}
// Item

View file

@ -56,9 +56,7 @@ public class ItemLithiumIonBatpack extends ItemArmor implements IEnergyItemInfo
public int transferLimit = 2_000;
public ItemLithiumIonBatpack() {
super(ArmorMaterial.DIAMOND, EntityEquipmentSlot.CHEST, (new Item.Builder()).group(ItemGroup.COMBAT));
//TODO: move to builder
//setMaxStackSize(1);
super(ArmorMaterial.DIAMOND, EntityEquipmentSlot.CHEST, new Item.Properties().maxStackSize(1));
}
public static void distributePowerToInventory(World world, EntityPlayer player, ItemStack itemStack, int maxSend) {

View file

@ -27,6 +27,7 @@ package techreborn.items.armor;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.*;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.events.TRRecipeHandler;
/**
@ -41,7 +42,7 @@ public class ItemTRArmour extends ItemArmor {
}
public ItemTRArmour(IArmorMaterial material, EntityEquipmentSlot slot, String repairOreDict) {
super(material, slot, (new Item.Properties()).group(ItemGroup.COMBAT));
super(material, slot, (new Item.Properties()).group(TechReborn.ITEMGROUP).maxStackSize(1));
this.repairOreDict = repairOreDict;
if (slot == EntityEquipmentSlot.HEAD)
//setTranslationKey(material.name().toLowerCase() + "Helmet");

View file

@ -39,6 +39,7 @@ import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.PoweredItemContainerProvider;
import reborncore.common.powerSystem.forge.ForgePowerItemManager;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import javax.annotation.Nullable;
@ -48,15 +49,13 @@ public class ItemBattery extends Item implements IEnergyItemInfo {
int maxTransfer = 0;
public ItemBattery(int maxEnergy, int maxTransfer) {
super();
setMaxStackSize(1);
setMaxDamage(1);
super(new Item.Properties().group(TechReborn.ITEMGROUP).maxStackSize(1).defaultMaxDamage(1));
this.maxEnergy = maxEnergy;
this.maxTransfer = maxTransfer;
this.addPropertyOverride(new ResourceLocation("techreborn:empty"), new IItemPropertyGetter() {
@Override
@OnlyIn(Dist.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
public float call(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
if (!stack.isEmpty() && new ForgePowerItemManager(stack).getEnergyStored() == 0) {
return 1.0F;
}

View file

@ -24,7 +24,7 @@
package techreborn.items.battery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
@ -39,19 +39,18 @@ public class ItemEnergyCrystal extends ItemBattery {
public ItemEnergyCrystal() {
super(ConfigTechReborn.EnergyCrystalMaxCharge, 1_000);
}
@OnlyIn(Dist.CLIENT)
@Override
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
if (!isInCreativeTab(par2CreativeTabs)) {
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
if (!isInGroup(group)) {
return;
}
ItemStack stack = new ItemStack(TRContent.ENERGY_CRYSTAL);
ItemStack charged = stack.copy();
ItemStack uncharged = new ItemStack(TRContent.ENERGY_CRYSTAL);
ItemStack charged = new ItemStack(TRContent.ENERGY_CRYSTAL);
ForgePowerItemManager capEnergy = new ForgePowerItemManager(charged);
capEnergy.setEnergyStored(capEnergy.getMaxEnergyStored());
itemList.add(stack);
itemList.add(charged);
items.add(uncharged);
items.add(charged);
}
}

View file

@ -24,7 +24,7 @@
package techreborn.items.battery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
@ -39,19 +39,18 @@ public class ItemLapotronCrystal extends ItemBattery {
public ItemLapotronCrystal() {
super(ConfigTechReborn.LapotronCrystalMaxCharge, 10_000);
}
@OnlyIn(Dist.CLIENT)
@Override
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
if (!isInCreativeTab(par2CreativeTabs)) {
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
if (!isInGroup(group)) {
return;
}
ItemStack stack = new ItemStack(TRContent.LAPOTRON_CRYSTAL);
ItemStack charged = stack.copy();
ItemStack uncharged = new ItemStack(TRContent.LAPOTRON_CRYSTAL);
ItemStack charged = new ItemStack(TRContent.LAPOTRON_CRYSTAL);
ForgePowerItemManager capEnergy = new ForgePowerItemManager(charged);
capEnergy.setEnergyStored(capEnergy.getMaxEnergyStored());
itemList.add(stack);
itemList.add(charged);
items.add(uncharged);
items.add(charged);
}
}

View file

@ -24,7 +24,7 @@
package techreborn.items.battery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
@ -39,19 +39,18 @@ public class ItemLapotronicOrb extends ItemBattery {
public ItemLapotronicOrb() {
super(ConfigTechReborn.LapotronicOrbMaxCharge, 100_000);
}
@OnlyIn(Dist.CLIENT)
@Override
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
if (!isInCreativeTab(par2CreativeTabs)) {
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
if (!isInGroup(group)) {
return;
}
ItemStack stack = new ItemStack(TRContent.LAPOTRONIC_ORB);
ItemStack charged = stack.copy();
ItemStack uncharged = new ItemStack(TRContent.LAPOTRONIC_ORB);
ItemStack charged = new ItemStack(TRContent.LAPOTRONIC_ORB);
ForgePowerItemManager capEnergy = new ForgePowerItemManager(charged);
capEnergy.setEnergyStored(capEnergy.getMaxEnergyStored());
itemList.add(stack);
itemList.add(charged);
items.add(uncharged);
items.add(charged);
}
}

View file

@ -24,7 +24,7 @@
package techreborn.items.battery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
@ -38,20 +38,19 @@ public class ItemLithiumIonBattery extends ItemBattery {
public ItemLithiumIonBattery() {
super(400_000, 1_000);
}
@OnlyIn(Dist.CLIENT)
@Override
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
if (!isInCreativeTab(par2CreativeTabs)) {
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
if (!isInGroup(group)) {
return;
}
ItemStack stack = new ItemStack(TRContent.LITHIUM_ION_BATTERY);
ItemStack charged = stack.copy();
ItemStack uncharged = new ItemStack(TRContent.LITHIUM_ION_BATTERY);
ItemStack charged = new ItemStack(TRContent.LITHIUM_ION_BATTERY);
ForgePowerItemManager capEnergy = new ForgePowerItemManager(charged);
capEnergy.setEnergyStored(capEnergy.getMaxEnergyStored());
itemList.add(stack);
itemList.add(charged);
items.add(uncharged);
items.add(charged);
}
}

View file

@ -24,7 +24,7 @@
package techreborn.items.battery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
@ -38,19 +38,18 @@ public class ItemRedCellBattery extends ItemBattery {
public ItemRedCellBattery() {
super(40_000, 100);
}
@OnlyIn(Dist.CLIENT)
@Override
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
if (!isInCreativeTab(par2CreativeTabs)) {
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
if (!isInGroup(group)) {
return;
}
ItemStack stack = new ItemStack(TRContent.LITHIUM_ION_BATTERY);
ItemStack charged = stack.copy();
ItemStack uncharged = new ItemStack(TRContent.RED_CELL_BATTERY);
ItemStack charged = new ItemStack(TRContent.RED_CELL_BATTERY);
ForgePowerItemManager capEnergy = new ForgePowerItemManager(charged);
capEnergy.setEnergyStored(capEnergy.getMaxEnergyStored());
itemList.add(stack);
itemList.add(charged);
items.add(uncharged);
items.add(charged);
}
}

View file

@ -8,15 +8,11 @@ import techreborn.TechReborn;
public class InitUtils {
public static <I extends Item> I setup(I item, String name) {
item.setRegistryName(new ResourceLocation(TechReborn.MOD_ID, name));
item.setTranslationKey(TechReborn.MOD_ID + "." + name);
item.setCreativeTab(TechReborn.TAB);
return item;
}
public static <B extends Block> B setup(B block, String name) {
block.setRegistryName(new ResourceLocation(TechReborn.MOD_ID, name));
block.setTranslationKey(TechReborn.MOD_ID + "." + name);
block.setCreativeTab(TechReborn.TAB);
return block;
}
}