Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A dropped torch now lights charcoal pits. Basics of Item size and wei…
…ght are in; lots of changes to registry stuff to accomodate itemBlocks. Only itemblocks are sized currently, will add to items next.
  • Loading branch information
alcatrazEscapee committed Jul 1, 2018
1 parent 025bf3e commit 89bae36
Show file tree
Hide file tree
Showing 19 changed files with 509 additions and 97 deletions.
55 changes: 29 additions & 26 deletions src/main/java/net/dries007/tfc/CommonEventHandler.java
Expand Up @@ -42,6 +42,7 @@ public class CommonEventHandler
* Make leaves drop sticks
*/
@SubscribeEvent
@SuppressWarnings("unused")
public static void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
{
final EntityPlayer harvester = event.getHarvester();
Expand All @@ -65,12 +66,12 @@ public static void onBlockHarvestDrops(BlockEvent.HarvestDropsEvent event)
* Note: `onBlockActivate` doesn't get called when the player is sneaking, unless doesSneakBypassUse returns true.
* We have this event already, might as well use it.
*/
@SuppressWarnings("unused")
@SubscribeEvent
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event)
{
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = world.getBlockState(pos);
ItemStack stack = event.getItemStack();
EntityPlayer player = event.getEntityPlayer();

Expand Down Expand Up @@ -123,6 +124,7 @@ If nothing happens (as per vanilla behavior, even if this event causes something
}
if (!world.isRemote)
{
// noinspection ConstantConditions
world.setBlockState(pos.offset(facing), BlocksTFC.CHARCOAL_PILE.getDefaultState());

if (!player.isCreative())
Expand Down Expand Up @@ -156,17 +158,17 @@ If nothing happens (as per vanilla behavior, even if this event causes something
player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, 1));
}
world.playSound(null, pos.offset(facing), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
event.setCanceled(true);
return;
}
else
{
// Insert log didn't work, see if trying to place another log pile
if (facing == EnumFacing.UP && te.countLogs() == 16)
if (facing == EnumFacing.UP && te.countLogs() == 16 || (facing != EnumFacing.UP && world.getBlockState(pos.down().offset(facing)).isNormalCube()
&& world.getBlockState(pos.offset(facing)).getBlock().isReplaceable(world, pos.offset(facing))))
{
// noinspection ConstantConditions
world.setBlockState(pos.offset(facing), BlocksTFC.LOG_PILE.getStateForPlacement(world, pos, facing, 0, 0, 0, 0, player));

TELogPile te2 = Helpers.getTE(world, pos, TELogPile.class);
TELogPile te2 = Helpers.getTE(world, pos.offset(facing), TELogPile.class);
if (te2 != null)
{
te2.insertLog(stack.copy());
Expand All @@ -179,39 +181,39 @@ If nothing happens (as per vanilla behavior, even if this event causes something
world.playSound(null, pos.offset(facing), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
event.setCanceled(true);
return;
}
}
}
if (world.getBlockState(pos.down().offset(facing)).isNormalCube() && !(world.getBlockState(pos.down().offset(facing)).getBlock() instanceof BlockLogPile)
&& world.getBlockState(pos.offset(facing)).getBlock().isReplaceable(world, pos.offset(facing)) &&
player.isSneaking())
else
{

if (!world.isRemote)
if (world.getBlockState(pos.down().offset(facing)).isNormalCube()
&& world.getBlockState(pos.offset(facing)).getBlock().isReplaceable(world, pos.offset(facing)) &&
player.isSneaking())
{
world.setBlockState(pos.offset(facing), BlocksTFC.LOG_PILE.getStateForPlacement(world, pos, facing, 0, 0, 0, 0, player));

TELogPile te = Helpers.getTE(world, pos, TELogPile.class);
if (te != null)
// Place log pile
if (!world.isRemote)
{
te.insertLog(stack.copy());
}
// noinspection ConstantConditions
world.setBlockState(pos.offset(facing), BlocksTFC.LOG_PILE.getStateForPlacement(world, pos, facing, 0, 0, 0, 0, player));

if (!player.capabilities.isCreativeMode)
{
player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, 1));
TELogPile te = Helpers.getTE(world, pos.offset(facing), TELogPile.class);
if (te != null)
{
te.insertLog(stack.copy());
}

if (!player.capabilities.isCreativeMode)
{
player.setHeldItem(event.getHand(), Helpers.consumeItem(stack, 1));
}
world.playSound(null, pos.offset(facing), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
world.playSound(null, pos.offset(facing), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
event.setCanceled(true);
return;
}
}
event.setCanceled(true);
return;
}
// TODO: Log Piles
// TODO: IPlaceableItem instances Call getBlockForPlacement or something like that
// Kiln Pottery
IFireable fireable = IFireable.fromItem(event.getItemStack().getItem());
if (fireable != null && event.getEntityPlayer().isSneaking() && event.getFace() == EnumFacing.UP)
Expand All @@ -236,5 +238,6 @@ If nothing happens (as per vanilla behavior, even if this event causes something
event.setCanceled(true);
}
}
// TODO: General placement behavior for IPlaceableItem
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/dries007/tfc/client/ClientEvents.java
Expand Up @@ -35,6 +35,7 @@
import net.dries007.tfc.TerraFirmaCraft;
import net.dries007.tfc.client.render.RenderFallingBlockTFC;
import net.dries007.tfc.objects.entity.EntityFallingBlockTFC;
import net.dries007.tfc.util.IItemSize;
import net.dries007.tfc.util.IMetalObject;
import net.dries007.tfc.world.classic.CalenderTFC;
import net.dries007.tfc.world.classic.ClimateTFC;
Expand Down Expand Up @@ -150,6 +151,10 @@ public static void onItemTooltip(ItemTooltipEvent event)
((IMetalObject) block).addMetalInfo(stack, tt);
}
}
if (item instanceof IItemSize)
{
((IItemSize) item).addSizeInfo(stack, tt);
}

int[] ids = OreDictionary.getOreIDs(stack);
if (ids != null && ids.length != 0)
Expand Down
Expand Up @@ -127,11 +127,12 @@ public static void registerModels(ModelRegistryEvent event)
ModelLoader.setCustomStateMapper(BlocksTFC.WORLD_ITEM, blockIn -> ImmutableMap.of(BlocksTFC.WORLD_ITEM.getDefaultState(), new ModelResourceLocation("tfc:empty")));
ClientRegistry.bindTileEntitySpecialRenderer(TEWorldItem.class, new TESRWorldItem());

for (Block block : BlocksTFC.getAllNormalItemBlocks())
for (Block block : BlocksTFC.getAllNormalItemBlocks().keySet())
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "normal"));

for (Block block : BlocksTFC.getAllInventoryItemBlocks())
for (Block block : BlocksTFC.getAllInventoryItemBlocks().keySet())
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));

}

@SubscribeEvent
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/net/dries007/tfc/objects/Size.java
@@ -0,0 +1,28 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.objects;

public enum Size
{
TINY("tiny", 64),
VERY_SMALL("very_small", 32),
SMALL("small", 16),
NORMAL("normal", 8),
LARGE("large", 4),
VERY_LARGE("very_large", 2),
HUGE("huge", 1);

public final int stackSize;
public final String name;

Size(String name, int stackSize)
{
this.name = name;
this.stackSize = stackSize;
}

}
23 changes: 23 additions & 0 deletions src/main/java/net/dries007/tfc/objects/Weight.java
@@ -0,0 +1,23 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*
*/

package net.dries007.tfc.objects;

public enum Weight
{
LIGHT("light", 4),
MEDIUM("medium", 2),
HEAVY("heavy", 1);

public final String name;
public final int multiplier;

Weight(String name, int multiplier)
{
this.name = name;
this.multiplier = multiplier;
}
}
13 changes: 6 additions & 7 deletions src/main/java/net/dries007/tfc/objects/blocks/BlockLogPile.java
Expand Up @@ -25,10 +25,7 @@
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
Expand Down Expand Up @@ -110,7 +107,8 @@ public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos,
{
if (stateIn.getValue(ONFIRE))
{
//NoTreePunching.proxy.generateParticle(worldIn, pos, 3);
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + rand.nextFloat(), pos.getY() + 1, pos.getZ() + rand.nextFloat(),
0f, 0.1f + 0.1f * rand.nextFloat(), 0f);
if (rand.nextDouble() < 0.4D)
{
worldIn.playSound((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 0.5F, 0.6F, false);
Expand All @@ -135,9 +133,10 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
{
// Light the Pile
if(world.getBlockState(pos.up()).getBlock().isReplaceable(world, pos)){
te.burning = true;
//te.burning = true;
world.setBlockState(pos, state.withProperty(ONFIRE, true));
te.tryLightNearby(world, pos);
te.light();
//te.tryLightNearby(world, pos);
world.setBlockState(pos.up(), Blocks.FIRE.getDefaultState());
world.playSound(null,pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS,1.0F,1.0F);
}
Expand Down

0 comments on commit 89bae36

Please sign in to comment.