Started adding single-component panel blocks. Very WIP
This commit is contained in:
parent
2d06c96e46
commit
92b00f199c
|
@ -115,6 +115,7 @@ public class IndustrialWires {
|
|||
GameRegistry.registerTileEntity(TileEntityRSPanelConn.class, MODID + ":control_panel_rs");
|
||||
GameRegistry.registerTileEntity(TileEntityPanelCreator.class, MODID + ":panel_creator");
|
||||
GameRegistry.registerTileEntity(TileEntityUnfinishedPanel.class, MODID + ":unfinished_panel");
|
||||
GameRegistry.registerTileEntity(TileEntityComponentPanel.class, MODID + ":single_component_panel");
|
||||
if (IWConfig.enableConversion) {
|
||||
GameRegistry.registerTileEntity(TileEntityIEMotor.class, MODID + ":ieMotor");
|
||||
GameRegistry.registerTileEntity(TileEntityMechICtoIE.class, MODID + ":mechIcToIe");
|
||||
|
|
|
@ -78,16 +78,18 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
|
|||
@Override
|
||||
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
|
||||
switch (state.getValue(type)) {
|
||||
case TOP:
|
||||
return new TileEntityPanel();
|
||||
case RS_WIRE:
|
||||
return new TileEntityRSPanelConn();
|
||||
case CREATOR:
|
||||
return new TileEntityPanelCreator();
|
||||
case TOP:
|
||||
return new TileEntityPanel();
|
||||
case RS_WIRE:
|
||||
return new TileEntityRSPanelConn();
|
||||
case CREATOR:
|
||||
return new TileEntityPanelCreator();
|
||||
case UNFINISHED:
|
||||
return new TileEntityUnfinishedPanel();
|
||||
default:
|
||||
return null;
|
||||
case SINGLE_COMP:
|
||||
return new TileEntityComponentPanel();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,8 +157,11 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
|
|||
|
||||
@Override
|
||||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
for (int i = 0; i < BlockTypes_Panel.values().length; i++) {
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
BlockTypes_Panel[] values = BlockTypes_Panel.values();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (values[i].showInCreative()) {
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ public enum BlockTypes_Panel implements IStringSerializable {
|
|||
RS_WIRE,
|
||||
DUMMY,
|
||||
CREATOR,
|
||||
UNFINISHED;
|
||||
UNFINISHED,
|
||||
SINGLE_COMP;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
@ -37,4 +38,8 @@ public enum BlockTypes_Panel implements IStringSerializable {
|
|||
public boolean isPanelConnector() {
|
||||
return this != CREATOR && this != UNFINISHED;
|
||||
}
|
||||
|
||||
public boolean showInCreative() {
|
||||
return this != SINGLE_COMP;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016-2017 malte0811
|
||||
*
|
||||
* Industrial Wires is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Industrial Wires is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package malte0811.industrialWires.blocks.controlpanel;
|
||||
|
||||
public class TileEntityComponentPanel extends TileEntityPanel {
|
||||
|
||||
}
|
|
@ -20,21 +20,30 @@ package malte0811.industrialWires.items;
|
|||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.client.ClientProxy;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
|
||||
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
|
||||
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
@ -164,6 +173,49 @@ public class ItemPanelComponent extends Item implements INetGUIItem {
|
|||
return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
|
||||
}
|
||||
|
||||
/**
|
||||
* mostly copied from {@link net.minecraft.item.ItemBlock}
|
||||
*/
|
||||
@Nonnull
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (!block.isReplaceable(worldIn, pos)) {
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(IndustrialWires.panel, pos, false, facing, (Entity) null)) {
|
||||
placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ);
|
||||
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
itemstack.shrink(1);
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
} else {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
private void placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
IBlockState state = IndustrialWires.panel.getStateFromMeta(BlockTypes_Panel.SINGLE_COMP.ordinal());
|
||||
world.setBlockState(pos, state);
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof IEBlockInterfaces.IDirectionalTile) {
|
||||
EnumFacing dir = ((IEBlockInterfaces.IDirectionalTile) te).getFacingForPlacement(player, pos, side, hitX, hitY, hitZ);
|
||||
((IEBlockInterfaces.IDirectionalTile) te).setFacing(dir);
|
||||
}
|
||||
if (te instanceof IEBlockInterfaces.ITileDrop) {
|
||||
((IEBlockInterfaces.ITileDrop) te).readOnPlacement(player, stack);
|
||||
}
|
||||
if (te instanceof TileEntityPanel) {
|
||||
((TileEntityPanel) te).getComponents().clear();
|
||||
((TileEntityPanel) te).getComponents().add(componentFromStack(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(NBTTagCompound data, EntityPlayer player, EnumHand hand) {
|
||||
ItemStack held = player.getHeldItem(hand);
|
||||
|
|
|
@ -67,6 +67,9 @@
|
|||
},
|
||||
"unfinished": {
|
||||
"model": "industrialwires:smartmodel/panel"
|
||||
},
|
||||
"single_comp": {
|
||||
"model": "industrialwires:smartmodel/panel_single_comp"
|
||||
}
|
||||
},
|
||||
"inventory,type=rs_wire": {
|
||||
|
|
Loading…
Reference in a new issue