Search in sources :

Example 1 with CampfireTileEntity

use of net.minecraft.tileentity.CampfireTileEntity in project FrostedHeart by TeamMoegMC.

the class CampfireBlockMixin method onBlockActivated.

/**
 * @author dashuaibia
 * @reason ignition
 */
@Overwrite
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof CampfireTileEntity) {
        CampfireTileEntity campfiretileentity = (CampfireTileEntity) tileentity;
        ItemStack itemstack = player.getHeldItem(handIn);
        if (!player.getHeldItemMainhand().isEmpty()) {
            if (CampfireBlock.canBeLit(state)) {
                if (itemstack.getItem() == Items.FLINT && player.getHeldItemOffhand().getItem() == Items.FLINT) {
                    Random rand = worldIn.rand;
                    player.swingArm(Hand.MAIN_HAND);
                    if (rand.nextFloat() < 0.33 && !worldIn.isRemote) {
                        worldIn.setBlockState(pos, state.with(BlockStateProperties.LIT, Boolean.valueOf(true)), 3);
                    }
                    worldIn.playSound(null, pos, SoundEvents.BLOCK_STONE_STEP, SoundCategory.BLOCKS, 1.0F, 2F + rand.nextFloat() * 0.4F);
                    if (worldIn.isRemote) {
                        for (int i = 0; i < 5; i++) {
                            worldIn.addParticle(ParticleTypes.SMOKE, player.getPosX() + player.getLookVec().getX() + rand.nextFloat() * 0.25, player.getPosY() + 0.5f + rand.nextFloat() * 0.25, player.getPosZ() + player.getLookVec().getZ() + rand.nextFloat() * 0.25, 0, 0.01, 0);
                        }
                        worldIn.addParticle(ParticleTypes.FLAME, player.getPosX() + player.getLookVec().getX() + rand.nextFloat() * 0.25, player.getPosY() + 0.5f + rand.nextFloat() * 0.25, player.getPosZ() + player.getLookVec().getZ() + rand.nextFloat() * 0.25, 0, 0.01, 0);
                    }
                    return ActionResultType.SUCCESS;
                }
            }
            Optional<CampfireCookingRecipe> optional = campfiretileentity.findMatchingRecipe(itemstack);
            if (optional.isPresent()) {
                if (!worldIn.isRemote && campfiretileentity.addItem(player.abilities.isCreativeMode ? itemstack.copy() : itemstack, optional.get().getCookTime())) {
                    player.addStat(Stats.INTERACT_WITH_CAMPFIRE);
                    return ActionResultType.CONSUME;
                }
            }
        } else {
            ICampfireExtra info = (ICampfireExtra) campfiretileentity;
            if (!worldIn.isRemote)
                if (state.get(CampfireBlock.LIT)) {
                    player.sendMessage(GuiUtils.translateMessage("campfire.remaining", Integer.toString(info.getLifeTime() / 20)), player.getUniqueID());
                } else if (info.getLifeTime() > 0) {
                    player.sendMessage(GuiUtils.translateMessage("campfire.ignition"), player.getUniqueID());
                } else {
                    player.sendMessage(GuiUtils.translateMessage("campfire.fuel"), player.getUniqueID());
                }
            return ActionResultType.SUCCESS;
        }
    }
    return ActionResultType.PASS;
}
Also used : CampfireTileEntity(net.minecraft.tileentity.CampfireTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) CampfireTileEntity(net.minecraft.tileentity.CampfireTileEntity) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) ICampfireExtra(com.teammoeg.frostedheart.util.ICampfireExtra) CampfireCookingRecipe(net.minecraft.item.crafting.CampfireCookingRecipe) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with CampfireTileEntity

use of net.minecraft.tileentity.CampfireTileEntity in project FrostedHeart by TeamMoegMC.

the class CampfireBlockMixin method onEntityCollision.

@Inject(at = @At("HEAD"), method = "onEntityCollision")
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo callbackInfo) {
    if (entityIn instanceof ItemEntity) {
        int rawBurnTime = ForgeHooks.getBurnTime(((ItemEntity) entityIn).getItem());
        if (worldIn.isRemote && isLit(state) && rawBurnTime > 0)
            worldIn.addParticle(ParticleTypes.SMOKE, entityIn.getPosX(), entityIn.getPosY() + 0.25D, entityIn.getPosZ(), 0, 0.05D, 0);
        if (rawBurnTime > 0) {
            if (((ItemEntity) entityIn).getThrowerId() != null && ((ICampfireExtra) worldIn.getTileEntity(pos)).getLifeTime() != -1337) {
                if (!worldIn.isRemote) {
                    int burnTime = rawBurnTime * 3 * ((ItemEntity) entityIn).getItem().getCount();
                    CampfireTileEntity tileEntity = (CampfireTileEntity) worldIn.getTileEntity(pos);
                    ICampfireExtra lifeTime = ((ICampfireExtra) tileEntity);
                    if (lifeTime.getLifeTime() < 19200 && lifeTime.getLifeTime() >= 0) {
                        lifeTime.addLifeTime(burnTime);
                        if (((ItemEntity) entityIn).getItem().getItem() == Items.LAVA_BUCKET)
                            InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.BUCKET));
                        entityIn.remove();
                    }
                }
            }
        }
    }
}
Also used : CampfireTileEntity(net.minecraft.tileentity.CampfireTileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack) ICampfireExtra(com.teammoeg.frostedheart.util.ICampfireExtra) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ICampfireExtra (com.teammoeg.frostedheart.util.ICampfireExtra)2 ItemStack (net.minecraft.item.ItemStack)2 CampfireTileEntity (net.minecraft.tileentity.CampfireTileEntity)2 Random (java.util.Random)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 CampfireCookingRecipe (net.minecraft.item.crafting.CampfireCookingRecipe)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1