Java Code Examples for net.minecraft.util.math.MathHelper#ceil()

The following examples show how to use net.minecraft.util.math.MathHelper#ceil() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityDabSquirrel.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void fall(float distance, float damageMultiplier) {
	if (distance > 1.0F) {
		this.playSound(SoundEvents.ENTITY_HORSE_LAND, 0.4F, 1.0F);
	}

	int i = MathHelper.ceil((distance * 0.5F - 3.0F) * damageMultiplier);

	if (i > 0) {
		this.attackEntityFrom(DamageSource.FALL, i);

		if (this.isBeingRidden()) {
			for (Entity entity : this.getRecursivePassengers()) {
				entity.attackEntityFrom(DamageSource.FALL, i);
			}
		}
		BlockPos pos = new BlockPos(this.posX, this.posY - 0.2D - this.prevRotationYaw, this.posZ);
		IBlockState iblockstate = this.world.getBlockState(pos);
		Block block = iblockstate.getBlock();

		if (iblockstate.getMaterial() != Material.AIR && !this.isSilent()) {
			SoundType soundtype = block.getSoundType(block.getDefaultState(), this.world, pos, this);
			this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, soundtype.getStepSound(), this.getSoundCategory(), soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
		}
	}
}
 
Example 2
Source File: EntityUtils.java    From ForgeHax with MIT License 6 votes vote down vote up
public static boolean isInWater(Entity entity) {
  if (entity == null) {
    return false;
  }
  
  double y = entity.posY + 0.01;
  
  for (int x = MathHelper.floor(entity.posX); x < MathHelper.ceil(entity.posX); x++) {
    for (int z = MathHelper.floor(entity.posZ); z < MathHelper.ceil(entity.posZ); z++) {
      BlockPos pos = new BlockPos(x, (int) y, z);
      
      if (getWorld().getBlockState(pos).getBlock() instanceof BlockLiquid) {
        return true;
      }
    }
  }
  
  return false;
}
 
Example 3
Source File: EntityUtils.java    From ForgeHax with MIT License 6 votes vote down vote up
public static boolean isAboveWater(Entity entity, boolean packet) {
  if (entity == null) {
    return false;
  }
  
  double y =
      entity.posY
          - (packet
          ? 0.03
          : (EntityUtils.isPlayer(entity)
              ? 0.2
              : 0.5)); // increasing this seems to flag more in NCP but needs to be increased
  // so the player lands on solid water
  
  for (int x = MathHelper.floor(entity.posX); x < MathHelper.ceil(entity.posX); x++) {
    for (int z = MathHelper.floor(entity.posZ); z < MathHelper.ceil(entity.posZ); z++) {
      BlockPos pos = new BlockPos(x, MathHelper.floor(y), z);
      
      if (getWorld().getBlockState(pos).getBlock() instanceof BlockLiquid) {
        return true;
      }
    }
  }
  
  return false;
}
 
Example 4
Source File: Jesus.java    From ForgeHax with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static boolean isAboveLand(Entity entity) {
  if (entity == null) {
    return false;
  }
  
  double y = entity.posY - 0.01;
  
  for (int x = MathHelper.floor(entity.posX); x < MathHelper.ceil(entity.posX); x++) {
    for (int z = MathHelper.floor(entity.posZ); z < MathHelper.ceil(entity.posZ); z++) {
      BlockPos pos = new BlockPos(x, MathHelper.floor(y), z);
      
      if (getWorld().getBlockState(pos).getBlock().isFullBlock(getWorld().getBlockState(pos))) {
        return true;
      }
    }
  }
  
  return false;
}
 
Example 5
Source File: LargeTurbineWorkableHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public long getRecipeOutputVoltage() {
    MetaTileEntityRotorHolder rotorHolder = largeTurbine.getAbilities(MetaTileEntityLargeTurbine.ABILITY_ROTOR_HOLDER).get(0);
    double relativeRotorSpeed = rotorHolder.getRelativeRotorSpeed();
    if (rotorHolder.getCurrentRotorSpeed() > 0 && rotorHolder.hasRotorInInventory()) {
        double rotorEfficiency = rotorHolder.getRotorEfficiency();
        double totalEnergyOutput = (BASE_EU_OUTPUT + getBonusForTurbineType(largeTurbine) * rotorEfficiency) * (relativeRotorSpeed * relativeRotorSpeed);
        return MathHelper.ceil(totalEnergyOutput);
    }
    return 0L;
}
 
Example 6
Source File: EntityFallingBlockEU.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fall(float distance, float damageMultiplier)
{
    Block block = this.blockState.getBlock();

    if (this.hurtEntities)
    {
        int i = MathHelper.ceil(distance - 1.0F);

        if (i > 0)
        {
            boolean isAnvil = block == Blocks.ANVIL;
            List<Entity> list = Lists.newArrayList(this.getEntityWorld().getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox()));
            DamageSource damageSource = isAnvil ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK;

            for (Entity entity : list)
            {
                entity.attackEntityFrom(damageSource, Math.min(MathHelper.floor(i * this.fallHurtAmount), this.fallHurtMax));
            }

            if (isAnvil && this.rand.nextFloat() < 0.05D + i * 0.05D)
            {
                int j = this.blockState.getValue(BlockAnvil.DAMAGE).intValue() + 1;

                if (j > 2)
                {
                    this.canSetAsBlock = false;
                }
                else
                {
                    this.blockState = this.blockState.withProperty(BlockAnvil.DAMAGE, Integer.valueOf(j));
                }
            }
        }
    }
}
 
Example 7
Source File: ModToolLeveling.java    From TinkersToolLeveling with MIT License 5 votes vote down vote up
@Override
public void afterHit(EntityProjectileBase projectile, World world, ItemStack ammoStack, EntityLivingBase attacker, Entity target, double impactSpeed) {
  if(impactSpeed > 0.4f && attacker instanceof EntityPlayer) {
    ItemStack launcher = projectile.tinkerProjectile.getLaunchingStack();
    if(launcher.getItem() instanceof BowCore) {
      double drawTime = ((BowCore) launcher.getItem()).getDrawTime();
      double drawSpeed = ProjectileLauncherNBT.from(launcher).drawSpeed;
      double drawTimeInSeconds = 1d / (20d * drawSpeed/drawTime);
      // we award 5 xp per 1s draw time
      int xp = MathHelper.ceil((5d * drawTimeInSeconds));
      this.addXp(launcher, xp, (EntityPlayer) attacker);
    }
  }
}
 
Example 8
Source File: ModuleEffectLeap.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Vec3d lookVec = spell.getData(LOOK);
	Entity target = spell.getVictim(world);

	if (!(target instanceof EntityLivingBase)) return true;

	ItemStack stack = ((EntityLivingBase) target).getHeldItemMainhand();
	if (stack.isEmpty()) return true;
	if (lookVec == null) return true;

	if (!target.hasNoGravity()) {
		double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell);
		if (!spellRing.taxCaster(world, spell, true)) return false;

		if (!NBTHelper.hasNBTEntry(stack, "jump_count")
				|| !NBTHelper.hasNBTEntry(stack, "max_jumps")
				|| !NBTHelper.hasNBTEntry(stack, "jump_timer")) {
			NBTHelper.setInt(stack, "jump_count", (int) potency);
			NBTHelper.setInt(stack, "max_jumps", (int) potency);
			NBTHelper.setInt(stack, "jump_timer", 200);
		}

		target.motionX += lookVec.x;
		target.motionY += 0.65;
		target.motionZ += lookVec.z;

		target.velocityChanged = true;
		target.fallDistance /= (1 + MathHelper.ceil(spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 8));

		if (target instanceof EntityPlayerMP)
			((EntityPlayerMP) target).connection.sendPacket(new SPacketEntityVelocity(target));
		world.playSound(null, target.getPosition(), ModSounds.FLY, SoundCategory.NEUTRAL, 1, 1);
	}
	return true;
}
 
Example 9
Source File: SlotItemHandlerFurnaceOutput.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onCrafting(ItemStack stack)
{
    stack.onCrafting(this.player.getEntityWorld(), this.player, this.amountCrafted);

    if (this.player.getEntityWorld().isRemote == false)
    {
        int i = this.amountCrafted;
        float f = FurnaceRecipes.instance().getSmeltingExperience(stack);

        if (f == 0.0F)
        {
            i = 0;
        }
        else if (f < 1.0F)
        {
            int j = MathHelper.floor((float)i * f);

            if (j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
            {
                ++j;
            }

            i = j;
        }

        while (i > 0)
        {
            int k = EntityXPOrb.getXPSplit(i);
            i -= k;
            this.player.getEntityWorld().spawnEntity(new EntityXPOrb(this.player.getEntityWorld(), this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k));
        }
    }

    this.amountCrafted = 0;
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);
}
 
Example 10
Source File: GuiComponentSideSelector.java    From OpenModsLib with MIT License 5 votes vote down vote up
public GuiComponentSideSelector(int x, int y, double scale, IBlockState blockState, TileEntity te, boolean highlightSelectedSides) {
	super(x, y);
	this.scale = scale;
	this.diameter = MathHelper.ceil(scale * SQRT_3);
	this.blockState = blockState;
	this.te = te;
	this.access = new FakeBlockAccess(blockState, te);
	this.highlightSelectedSides = highlightSelectedSides;
}
 
Example 11
Source File: LargeTurbineWorkableHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public long getMaxVoltage() {
    MetaTileEntityRotorHolder rotorHolder = largeTurbine.getAbilities(MetaTileEntityLargeTurbine.ABILITY_ROTOR_HOLDER).get(0);
    if (rotorHolder.hasRotorInInventory()) {
        double rotorEfficiency = rotorHolder.getRotorEfficiency();
        double totalEnergyOutput = (BASE_EU_OUTPUT + getBonusForTurbineType(largeTurbine) * rotorEfficiency);
        return MathHelper.ceil(totalEnergyOutput);
    }
    return BASE_EU_OUTPUT + getBonusForTurbineType(largeTurbine);
}
 
Example 12
Source File: MixinTitleScreen.java    From OptiFabric with Mozilla Public License 2.0 5 votes vote down vote up
@Inject(method = "render", at = @At("RETURN"))
private void render(int int_1, int int_2, float float_1, CallbackInfo info) {
	if (!OptifabricError.hasError()) {
		float fadeTime = this.doBackgroundFade ? (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
		float fadeColor = this.doBackgroundFade ? MathHelper.clamp(fadeTime - 1.0F, 0.0F, 1.0F) : 1.0F;

		int int_6 = MathHelper.ceil(fadeColor * 255.0F) << 24;
		if ((int_6 & -67108864) != 0) {
			this.drawString(this.font, OptifineVersion.version, 2, this.height - 20, 16777215 | int_6);
		}
	}
}
 
Example 13
Source File: HallowedOreFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, HallowedOreFeatureConfig oreFeatureConfig) {
	float randomNumberFromZeroToPi = random.nextFloat() * 3.1415927F;
	float dividedSize = (float) oreFeatureConfig.size / 8.0F;
	int ceilSize = MathHelper.ceil(((float) oreFeatureConfig.size / 16.0F * 2.0F + 1.0F) / 2.0F);
	double positiveX = (blockPos.getX() + MathHelper.sin(randomNumberFromZeroToPi) * dividedSize);
	double negativeX = (blockPos.getX() - MathHelper.sin(randomNumberFromZeroToPi) * dividedSize);
	double positiveZ = (blockPos.getZ() + MathHelper.cos(randomNumberFromZeroToPi) * dividedSize);
	double negativeZ = (blockPos.getZ() - MathHelper.cos(randomNumberFromZeroToPi) * dividedSize);
	double positiveY = (blockPos.getY() + random.nextInt(3) - 2);
	double negativeY = (blockPos.getY() + random.nextInt(3) - 2);
	int startX = blockPos.getX() - MathHelper.ceil(dividedSize) - ceilSize;
	int y = blockPos.getY() - 2 - ceilSize;
	int startZ = blockPos.getZ() - MathHelper.ceil(dividedSize) - ceilSize;
	int xSize = 2 * (MathHelper.ceil(dividedSize) + ceilSize);
	int int_7 = 2 * (2 + ceilSize);
	
	for (int x = startX; x <= startX + xSize; ++x) {
		for (int z = startZ; z <= startZ + xSize; ++z) {
			if (y <= world.getTopY(Type.OCEAN_FLOOR_WG, x, z)) {
				return this.generateVeinPart(world, random, oreFeatureConfig, positiveX, negativeX, positiveZ, negativeZ, positiveY, negativeY, startX, y, startZ, xSize, int_7);
			}
		}
	}
	
	return false;
}
 
Example 14
Source File: SandboxTitleScreen.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void render(int int_1, int int_2, float float_1) {
    if (this.backgroundFadeStart == 0L && this.doBackgroundFade) {
        this.backgroundFadeStart = Util.getMeasuringTimeMs();
    }

    float float_2 = this.doBackgroundFade ? (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
    fill(0, 0, this.width, this.height, -1);
    this.backgroundRenderer.render(float_1, MathHelper.clamp(float_2, 0.0F, 1.0F));
    int int_4 = this.width / 2 - 137;
    this.minecraft.getTextureManager().bindTexture(PANORAMA_OVERLAY);
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA.value, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA.value);
    GlStateManager.color4f(1.0F, 1.0F, 1.0F, this.doBackgroundFade ? (float) MathHelper.ceil(MathHelper.clamp(float_2, 0.0F, 1.0F)) : 1.0F);
    blit(0, 0, this.width, this.height, 0.0F, 0.0F, 16, 128, 16, 128);
    float float_3 = this.doBackgroundFade ? MathHelper.clamp(float_2 - 1.0F, 0.0F, 1.0F) : 1.0F;
    int int_6 = MathHelper.ceil(float_3 * 255.0F) << 24;
    if ((int_6 & -67108864) != 0) {
        this.minecraft.getTextureManager().bindTexture(MINECRAFT_TITLE_TEXTURE);
        GlStateManager.color4f(1.0F, 1.0F, 1.0F, float_3);
        if (this.field_17776) {
            this.blit(int_4 + 0, 30, 0, 0, 99, 44);
            this.blit(int_4 + 99, 30, 129, 0, 27, 44);
            this.blit(int_4 + 99 + 26, 30, 126, 0, 3, 44);
            this.blit(int_4 + 99 + 26 + 3, 30, 99, 0, 26, 44);
            this.blit(int_4 + 155, 30, 0, 45, 155, 44);
        } else {
            this.blit(int_4 + 0, 30, 0, 0, 155, 44);
            this.blit(int_4 + 155, 30, 0, 45, 155, 44);
        }

        this.minecraft.getTextureManager().bindTexture(EDITION_TITLE_TEXTURE);
        blit(int_4 + 88, 67, 0.0F, 0.0F, 98, 14, 128, 16);
        if (this.splashText != null) {
            GlStateManager.pushMatrix();
            GlStateManager.translatef((float) (this.width / 2 + 90), 70.0F, 0.0F);
            GlStateManager.rotatef(-20.0F, 0.0F, 0.0F, 1.0F);
            float float_4 = 1.8F - MathHelper.abs(MathHelper.sin((float) (Util.getMeasuringTimeMs() % 1000L) / 1000.0F * 6.2831855F) * 0.1F);
            float_4 = float_4 * 100.0F / (float) (this.font.getStringWidth(this.splashText) + 32);
            GlStateManager.scalef(float_4, float_4, float_4);
            this.drawCenteredString(this.font, this.splashText, 0, -8, 16776960 | int_6);
            GlStateManager.popMatrix();
        }

        String string_1 = "Minecraft " + SharedConstants.getGameVersion().getName();
        if (this.minecraft.isDemo()) {
            string_1 = string_1 + " Demo";
        } else {
            string_1 = string_1 + ("release".equalsIgnoreCase(this.minecraft.getVersionType()) ? "" : "/" + this.minecraft.getVersionType());
        }

        this.drawString(this.font, string_1, 2, this.height - 10, 16777215 | int_6);
        this.drawString(this.font, "Copyright Mojang AB. Do not distribute!", this.copyrightTextX, this.height - 10, 16777215 | int_6);
        if (int_1 > this.copyrightTextX && int_1 < this.copyrightTextX + this.copyrightTextWidth && int_2 > this.height - 10 && int_2 < this.height) {
            fill(this.copyrightTextX, this.height - 1, this.copyrightTextX + this.copyrightTextWidth, this.height, 16777215 | int_6);
        }

        if (this.warning != null) {
            this.warning.render(int_6);
        }

        Iterator var11 = this.buttons.iterator();

        while (var11.hasNext()) {
            AbstractButtonWidget abstractButtonWidget_1 = (AbstractButtonWidget) var11.next();
            abstractButtonWidget_1.setAlpha(float_3);
        }

        super.render(int_1, int_2, float_1);

    }
}
 
Example 15
Source File: MixinEntity.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "updateMovementInFluid", at = @At("HEAD"), cancellable = true)
private void modifyFluidMovementBoundingBox(Tag<Fluid> fluidTag, double d, CallbackInfoReturnable<Boolean> ci) {
    if (ConnectionInfo.protocolVersion > Protocols.V1_12_2)
        return;

    Box box = getBoundingBox().expand(0, -0.4, 0).contract(0.001);
    int minX = MathHelper.floor(box.minX);
    int maxX = MathHelper.ceil(box.maxX);
    int minY = MathHelper.floor(box.minY);
    int maxY = MathHelper.ceil(box.maxY);
    int minZ = MathHelper.floor(box.minZ);
    int maxZ = MathHelper.ceil(box.maxZ);

    if (!world.isRegionLoaded(minX, minY, minZ, maxX, maxY, maxZ))
        ci.setReturnValue(false);

    double waterHeight = 0;
    boolean foundFluid = false;
    Vec3d pushVec = Vec3d.ZERO;

    BlockPos.Mutable mutable = new BlockPos.Mutable();

    for (int x = minX; x < maxX; x++) {
        for (int y = minY - 1; y < maxY; y++) {
            for (int z = minZ; z < maxZ; z++) {
                mutable.set(x, y, z);
                FluidState state = world.getFluidState(mutable);
                if (state.isIn(fluidTag)) {
                    double height = y + state.getHeight(world, mutable);
                    if (height >= box.minY - 0.4)
                        waterHeight = Math.max(height - box.minY + 0.4, waterHeight);
                    if (y >= minY && maxY >= height) {
                        foundFluid = true;
                        pushVec = pushVec.add(state.getVelocity(world, mutable));
                    }
                }
            }
        }
    }

    if (pushVec.length() > 0) {
        pushVec = pushVec.normalize().multiply(0.014);
        setVelocity(getVelocity().add(pushVec));
    }

    this.fluidHeight.put(fluidTag, waterHeight);
    ci.setReturnValue(foundFluid);
}
 
Example 16
Source File: TorikkiIceSpike.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
    while (worldIn.isAirBlock(position) && position.getY() > 2) {
        position = position.down();
    }

    if (worldIn.getBlockState(position).getBlock() != Blocks.SNOW) {
        return false;
    } else {
        position = position.up(rand.nextInt(4));
        int i = rand.nextInt(4) + 7;
        int j = i / 4 + rand.nextInt(2);

        if (j > 1 && rand.nextInt(60) == 0) {
            position = position.up(10 + rand.nextInt(30));
        }

        for (int k = 0; k < i; ++k) {
            float f = (1.0F - (float) k / (float) i) * (float) j;
            int l = MathHelper.ceil(f);

            for (int i1 = -l; i1 <= l; ++i1) {
                float f1 = (float) MathHelper.abs(i1) - 0.25F;

                for (int j1 = -l; j1 <= l; ++j1) {
                    float f2 = (float) MathHelper.abs(j1) - 0.25F;

                    if ((i1 == 0 && j1 == 0 || f1 * f1 + f2 * f2 <= f * f) && (i1 != -l && i1 != l && j1 != -l && j1 != l || rand.nextFloat() <= 0.75F)) {
                        IBlockState iblockstate = worldIn.getBlockState(position.add(i1, k, j1));
                        Block block = iblockstate.getBlock();

                        if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
                            this.setBlockAndNotifyAdequately(worldIn, position.add(i1, k, j1), Blocks.PACKED_ICE.getDefaultState());
                        }

                        if (k != 0 && l > 1) {
                            iblockstate = worldIn.getBlockState(position.add(i1, -k, j1));
                            block = iblockstate.getBlock();

                            if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, -k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
                                this.setBlockAndNotifyAdequately(worldIn, position.add(i1, -k, j1), Blocks.PACKED_ICE.getDefaultState());
                            }
                        }
                    }
                }
            }
        }

        int k1 = j - 1;

        if (k1 < 0) {
            k1 = 0;
        } else if (k1 > 1) {
            k1 = 1;
        }

        for (int l1 = -k1; l1 <= k1; ++l1) {
            for (int i2 = -k1; i2 <= k1; ++i2) {
                BlockPos blockpos = position.add(l1, -1, i2);
                int j2 = 50;

                if (Math.abs(l1) == 1 && Math.abs(i2) == 1) {
                    j2 = rand.nextInt(5);
                }

                while (blockpos.getY() > 50) {
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
                    Block block1 = iblockstate1.getBlock();

                    if (!iblockstate1.getBlock().isAir(iblockstate1, worldIn, blockpos) && block1 != Blocks.DIRT && block1 != Blocks.SNOW && block1 != Blocks.ICE && block1 != Blocks.PACKED_ICE) {
                        break;
                    }

                    this.setBlockAndNotifyAdequately(worldIn, blockpos, Blocks.PACKED_ICE.getDefaultState());
                    blockpos = blockpos.down();
                    --j2;

                    if (j2 <= 0) {
                        blockpos = blockpos.down(rand.nextInt(5) + 1);
                        j2 = rand.nextInt(5);
                    }
                }
            }
        }

        return true;
    }
}
 
Example 17
Source File: SlotSaltFurnace.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
 */
@Override
protected void onCrafting(ItemStack par1ItemStack)
{
    par1ItemStack.onCrafting(this.thePlayer.world, this.thePlayer, this.field_75228_b);

    if (!this.thePlayer.world.isRemote)
    {
        int i = this.field_75228_b;
        float f = par1ItemStack.getItem() == ItemLoader.material ? 0.2f : par1ItemStack.getItem() == ItemLoader.nigari ? 0.3f : 0.0f;
        int j;

        if (f == 0.0F)
        {
            i = 0;
        }
        else if (f < 1.0F)
        {
            j = MathHelper.floor(i * f);

            if (j < MathHelper.ceil(i * f) && (float)Math.random() < i * f - j)
            {
                ++j;
            }

            i = j;
        }

        while (i > 0)
        {
            j = EntityXPOrb.getXPSplit(i);
            i -= j;
            this.thePlayer.world.spawnEntity(new EntityXPOrb(this.thePlayer.world, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j));
        }
    }

    this.field_75228_b = 0;


    if (par1ItemStack.getItem() == ItemLoader.material)
    {
        TofuAdvancements.grantAdvancement(this.thePlayer, "getsalt");
    }
    else if (par1ItemStack.getItem() == ItemLoader.nigari)
    {
        TofuAdvancements.grantAdvancement(this.thePlayer, "getnigari");
    }
}
 
Example 18
Source File: DefaultFabricationCategory.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public List<Widget> setupDisplay(DefaultFabricationDisplay recipeDisplay, Rectangle bounds) {
    final Point startPoint = new Point(bounds.getCenterX() - 81, bounds.getCenterY() - 41);

    class BaseWidget extends Widget {
        private BaseWidget() {
        }

        public void render(MatrixStack stack, int mouseX, int mouseY, float delta) {
            //super.render(mouseX, mouseY, delta);
            DiffuseLighting.disable();
            MinecraftClient.getInstance().getTextureManager().bindTexture(DefaultFabricationCategory.DISPLAY_TEXTURE);
            this.drawTexture(stack, startPoint.x, startPoint.y, 0, 0, 162, 82);

            int height = MathHelper.ceil((double) (System.currentTimeMillis() / 250L) % 14.0D / 1.0D);
            this.drawTexture(stack, startPoint.x + 2, startPoint.y + 21 + (14 - height), 82, 77 + (14 - height), 14, height);
            int width = MathHelper.ceil((double) (System.currentTimeMillis() / 250L) % 24.0D / 1.0D);
            this.drawTexture(stack, startPoint.x + 24, startPoint.y + 18, 82, 91, width, 17);
        }

        @Override
        public List<? extends Element> children() {
            return new ArrayList<>();
        }
    }

    List<Widget> widgets = new LinkedList<>();
    widgets.add(new BaseWidget());

    // Diamond input
    // Silicon
    // Silicon
    // Redstone
    // User input
    // Output
    widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entry(EntryStack.create(new ItemStack(Items.DIAMOND))));
    widgets.add(Widgets.createSlot(new Point(startPoint.x + (18 * 7) + 1, startPoint.y + 1)).entries(recipeDisplay.getInput().get(0)));

    widgets.add(Widgets.createSlot(new Point(startPoint.x + (18 * 3) + 1, startPoint.y + 47)).entry(EntryStack.create(new ItemStack(GalacticraftItems.RAW_SILICON))));
    widgets.add(Widgets.createSlot(new Point(startPoint.x + (18 * 3) + 1, startPoint.y + 47 + 18)).entry(EntryStack.create(new ItemStack(GalacticraftItems.RAW_SILICON))));
    widgets.add(Widgets.createSlot(new Point(startPoint.x + (18 * 6) + 1, startPoint.y + 47)).entry(EntryStack.create(new ItemStack(Items.REDSTONE))));

    widgets.add(Widgets.createSlot(new Point(startPoint.x + (18 * 8) + 1, startPoint.y + 47 + 18)).entries(recipeDisplay.getOutputEntries()));
    return widgets;
}
 
Example 19
Source File: SlotFirepitOutput.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
 */
@Override
protected void onCrafting(ItemStack stack)
{
	stack.onCrafting(this.player.world, this.player, this.removeCount);

	if (!this.player.world.isRemote)
	{
		int i = this.removeCount;
		float f = FurnaceRecipes.instance().getSmeltingExperience(stack);

		if (f == 0.0F)
		{
			i = 0;
		}
		else if (f < 1.0F)
		{
			int j = MathHelper.floor((float)i * f);

			if (j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
			{
				++j;
			}

			i = j;
		}

		while (i > 0)
		{
			int k = EntityXPOrb.getXPSplit(i);
			i -= k;
			this.player.world.spawnEntity(new EntityXPOrb(this.player.world, this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k));
		}
	}

	this.removeCount = 0;

	net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);

	if (stack.getItem() == Items.IRON_INGOT)
	{
		this.player.addStat(AchievementList.ACQUIRE_IRON);
	}

	if (stack.getItem() == Items.COOKED_FISH)
	{
		this.player.addStat(AchievementList.COOK_FISH);
	}
}
 
Example 20
Source File: DefaultCompressingCategory.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public List<Widget> setupDisplay(DefaultCompressingDisplay recipeDisplay, Rectangle bounds) {
    final Point startPoint = new Point(bounds.getCenterX() - 68, bounds.getCenterY() - 37);

    class BaseWidget extends Widget {
        BaseWidget() {
        }

        public void render(MatrixStack stack, int mouseX, int mouseY, float delta) {
            //super.render(stack, mouseX, mouseY, delta);
            DiffuseLighting.disable();
            MinecraftClient.getInstance().getTextureManager().bindTexture(DefaultCompressingCategory.DISPLAY_TEXTURE);
            this.drawTexture(stack, startPoint.x, startPoint.y, 0, 83, 137, 157);

            int height = MathHelper.ceil((double) (System.currentTimeMillis() / 250L) % 14.0D / 1.0D);
            this.drawTexture(stack, startPoint.x + 2, startPoint.y + 21 + (14 - height), 82, 77 + (14 - height), 14, height);
            int width = MathHelper.ceil((double) (System.currentTimeMillis() / 250L) % 24.0D / 1.0D);
            this.drawTexture(stack, startPoint.x + 24, startPoint.y + 18, 82, 91, width, 17);
        }

        @Override
        public List<? extends Element> children() {
            return new ArrayList<>();
        }
    }

    List<Widget> widgets = new LinkedList<>(Collections.singletonList(new BaseWidget()));
    List<List<EntryStack>> input = recipeDisplay.getInputEntries();
    List<Slot> slots = Lists.newArrayList();

    // 3x3 grid
    // Output
    int i;
    for (i = 0; i < 3; ++i) {
        for (int x = 0; x < 3; ++x) {
            slots.add(Widgets.createSlot(new Point(startPoint.x + (x * 18) + 1, startPoint.y + (i * 18) + 1)));
        }
    }
    for (i = 0; i < input.size(); ++i) {
        if (!input.get(i).isEmpty()) {
            slots.get(this.getSlotWithSize(recipeDisplay, i)).entries(input.get(i));
        }
    }

    widgets.addAll(slots);
    widgets.add(Widgets.createSlot(new Point(startPoint.x + 120, startPoint.y + (18) + 3)).entries(new ArrayList<>(Objects.requireNonNull(recipeDisplay).getOutputEntries())));

    widgets.add(Widgets.createSlot(new Point(startPoint.x + (2 * 18) + 1, startPoint.y + (18 * 3) + 4)).entries(AbstractFurnaceBlockEntity.createFuelTimeMap().keySet().stream().map(EntryStack::create).collect(Collectors.toList())));
    return widgets;
}