Skip to content

Commit

Permalink
Placable metal sheets. Rendering / blockstates / registry is done, ne…
Browse files Browse the repository at this point in the history
…ed to fix bounding boxes, etc.
  • Loading branch information
alcatrazEscapee committed Jul 2, 2018
1 parent 137f8e2 commit fbacd3c
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 4 deletions.
17 changes: 17 additions & 0 deletions generateResources.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,29 @@ def item(filename_parts, *layers, parent='item/generated'):
}
})

# ANVILS
for key in METAL_TYPES:
if METAL_TYPES[key]:
blockstate(('anvil', key), 'tfc:anvil', textures={
('all', 'particle'): 'tfc:blocks/metal/%s' % key
})

# METAL SHEETS
for key in METAL_TYPES:
blockstate(('sheet', key), 'tfc:sheet', textures={
('all', 'particle'): 'tfc:blocks/metal/%s' % key
}, variants={
'normal': None,
'face': {
'north': {'x': 90},
'east': {'y': 90, 'x': 90},
'south': {'y': 180, 'x': 90},
'west': {'y': 270, 'x': 90},
'up': {},
'down': {'x': 180}
}
})

# ROCK STUFF
for rock_type in ROCK_TYPES:
# FULL BLOCKS
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dries007/tfc/CommonEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ If nothing happens (as per vanilla behavior, even if this event causes something
{
ItemStack mainStack = player.getHeldItem(EnumHand.MAIN_HAND);
if ((mainStack.getItem() == Items.COAL && mainStack.getMetadata() == 1) ||
Helpers.doesStackMatchOre(mainStack, "logWood") ||
(Helpers.doesStackMatchOre(mainStack, "logWood") && player.isSneaking()) ||
mainStack.getItem() instanceof IPlacableItem)
{
event.setCanceled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public static void registerModels(ModelRegistryEvent event)
for (Block block : BlocksTFC.getAllAnvils())
ModelLoader.setCustomStateMapper(block, new StateMap.Builder().build());

for (Block block : BlocksTFC.getAllSheets())
ModelLoader.setCustomStateMapper(block, new StateMap.Builder().build());

for (BlockSlabTFC.Half block : BlocksTFC.getAllSlabBlocks())
{
ModelLoader.setCustomStateMapper(block, new StateMap.Builder().ignore(BlockSlabTFC.VARIANT).build());
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/net/dries007/tfc/objects/blocks/BlocksTFC.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.dries007.tfc.objects.Wood;
import net.dries007.tfc.objects.blocks.metal.BlockAnvilTFC;
import net.dries007.tfc.objects.blocks.metal.BlockIngotPile;
import net.dries007.tfc.objects.blocks.metal.BlockSheet;
import net.dries007.tfc.objects.blocks.stone.BlockButtonStoneTFC;
import net.dries007.tfc.objects.blocks.stone.BlockOreTFC;
import net.dries007.tfc.objects.blocks.stone.BlockRockVariant;
Expand Down Expand Up @@ -121,6 +122,7 @@ public final class BlocksTFC
private static ImmutableList<BlockSlabTFC.Half> allSlabBlocks;
private static ImmutableList<BlockChestTFC> allChestBlocks;
private static ImmutableList<BlockAnvilTFC> allAnvils;
private static ImmutableList<BlockSheet> allSheets;

public static ImmutableListMultimap<Block, Class<? extends ItemBlock>> getAllNormalItemBlocks()
{
Expand Down Expand Up @@ -202,6 +204,11 @@ public static ImmutableList<BlockAnvilTFC> getAllAnvils()
return allAnvils;
}

public static ImmutableList<BlockSheet> getAllSheets()
{
return allSheets;
}

@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
IForgeRegistry<Block> r = event.getRegistry();
Expand Down Expand Up @@ -333,13 +340,19 @@ public static void registerBlocks(RegistryEvent.Register<Block> event) {
}

{
Builder<BlockAnvilTFC> b = ImmutableList.builder();
Builder<BlockAnvilTFC> anvils = ImmutableList.builder();
Builder<BlockSheet> sheets = ImmutableList.builder();

for (Metal metal : Metal.values())
{
if (metal.hasType(Metal.ItemType.ANVIL))
b.add(register(r, "anvil/" + metal.name().toLowerCase(), new BlockAnvilTFC(metal), CT_METAL));
anvils.add(register(r, "anvil/" + metal.name().toLowerCase(), new BlockAnvilTFC(metal), CT_METAL));

sheets.add(register(r, "sheet/" + metal.name().toLowerCase(), new BlockSheet(metal), CT_METAL));
}

allAnvils = b.build();
allAnvils = anvils.build();
allSheets = sheets.build();
}

inventoryItemBlocks.put(register(r, "torch", new BlockTorchTFC(), CT_MISC), ItemBlockTorchTFC.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.objects.blocks.metal;

import java.util.EnumMap;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.objects.Metal;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockSheet extends Block
{
public static final PropertyDirection FACE = PropertyDirection.create("face");
private static final EnumMap<Metal, BlockSheet> MAP = new EnumMap<>(Metal.class);

public static BlockSheet get(Metal metal)
{
return MAP.get(metal);
}

public static ItemStack get(Metal metal, int amount)
{
return new ItemStack(MAP.get(metal), amount);
}

public final Metal metal;

public BlockSheet(Metal metal)
{
super(Material.IRON);

this.metal = metal;
if (MAP.put(metal, this) != null) throw new IllegalStateException("There can only be one.");

this.setDefaultState(blockState.getBaseState().withProperty(FACE, EnumFacing.NORTH));
}

@Override
@SuppressWarnings("deprecation")
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACE, EnumFacing.getFront(meta));
}

@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(FACE).getIndex();
}

@SuppressWarnings("deprecation")
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}

@SuppressWarnings("deprecation")
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FULL_BLOCK_AABB; // todo: proper bounding box
}

@SuppressWarnings("deprecation")
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}

@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, FACE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.objects.Wood;
import net.dries007.tfc.util.OreDictionaryHelper;

@MethodsReturnNonnullByDefault
public class BlockLogTFC extends BlockLog
{
public static final PropertyBool PLACED = PropertyBool.create("placed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import net.minecraft.world.World;

import net.dries007.tfc.objects.Metal;
import net.dries007.tfc.objects.blocks.metal.BlockSheet;
import net.dries007.tfc.util.IPlacableItem;

import static net.dries007.tfc.objects.blocks.metal.BlockSheet.FACE;

public class ItemSheet extends ItemMetal implements IPlacableItem
{
public ItemSheet(Metal metal, Metal.ItemType type)
Expand All @@ -24,6 +27,12 @@ public ItemSheet(Metal metal, Metal.ItemType type)
@Override
public boolean placeItemInWorld(World world, BlockPos pos, ItemStack stack, EnumFacing facing, EntityPlayer player)
{
if (world.getBlockState(pos).isNormalCube() && stack.getItem() instanceof ItemSheet)
{
ItemSheet sheet = (ItemSheet) stack.getItem();
world.setBlockState(pos.offset(facing), BlockSheet.get(sheet.metal).getDefaultState().withProperty(FACE, facing));
return true;
}
return false;
}
}
64 changes: 64 additions & 0 deletions src/main/resources/assets/tfc/models/block/sheet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [
0,
0,
0
],
"to": [
16,
1,
16
],
"faces": {
"north": {
"uv": [
0,
0,
16,
1
],
"texture": "#all"
},
"east": {
"uv": [
0,
0,
16,
1
],
"texture": "#all"
},
"south": {
"uv": [
0,
0,
16,
1
],
"texture": "#all"
},
"west": {
"uv": [
0,
0,
16,
1
],
"texture": "#all"
},
"up": {
"uv": [
0,
0,
16,
16
],
"texture": "#all"
}
}
}
]
}

0 comments on commit fbacd3c

Please sign in to comment.