Search in sources :

Example 1 with EntityGrist

use of com.mraof.minestuck.entity.item.EntityGrist in project Minestuck by mraof.

the class TileEntityCrockerMachine method processContents.

@Override
public void processContents() {
    switch(getMachineType()) {
        case GRIST_WIDGET:
            if (!world.isRemote) {
                ItemStack item = AlchemyRecipeHandler.getDecodedItem(inv.get(0));
                GristSet gristSet = GristRegistry.getGristConversion(item);
                if (item.getCount() != 1)
                    gristSet.scaleGrist(item.getCount());
                gristSet.scaleGrist(0.9F);
                if (item.isItemDamaged()) {
                    float multiplier = 1 - item.getItem().getDamage(item) / ((float) item.getMaxDamage());
                    for (GristAmount amount : gristSet.getArray()) {
                        gristSet.setGrist(amount.getType(), (int) (amount.getAmount() * multiplier));
                    }
                }
                for (Entry<GristType, Integer> entry : gristSet.getMap().entrySet()) {
                    int grist = entry.getValue();
                    while (true) {
                        if (grist == 0)
                            break;
                        GristAmount gristAmount = new GristAmount(entry.getKey(), grist <= 3 ? grist : (world.rand.nextInt(grist) + 1));
                        EntityGrist entity = new EntityGrist(world, this.pos.getX() + 0.5, /* this.width - this.width / 2 */
                        this.pos.getY() + 1, this.pos.getZ() + 0.5, /* this.width - this.width / 2 */
                        gristAmount);
                        entity.motionX /= 2;
                        entity.motionY /= 2;
                        entity.motionZ /= 2;
                        world.spawnEntity(entity);
                        // Create grist entity of gristAmount
                        grist -= gristAmount.getAmount();
                    }
                }
            }
            this.decrStackSize(0, 1);
            break;
    }
}
Also used : EntityGrist(com.mraof.minestuck.entity.item.EntityGrist) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EntityGrist

use of com.mraof.minestuck.entity.item.EntityGrist in project Minestuck by mraof.

the class EntityUnderling method onDeathUpdate.

@Override
protected void onDeathUpdate() {
    super.onDeathUpdate();
    if (this.deathTime == 20 && !this.world.isRemote) {
        GristSet grist = this.getGristSpoils();
        if (fromSpawner)
            grist.scaleGrist(0.5F);
        if (!dropCandy) {
            for (GristAmount gristType : grist.getArray()) this.world.spawnEntity(new EntityGrist(world, randX(), this.posY, randZ(), gristType));
        } else {
            for (GristAmount gristType : grist.getArray()) {
                int candy = (gristType.getAmount() + 2) / 4;
                int gristAmount = gristType.getAmount() - candy * 2;
                if (candy > 0)
                    this.world.spawnEntity(new EntityItem(world, randX(), this.posY, randZ(), new ItemStack(MinestuckItems.candy, candy, gristType.getType().getId() + 1)));
                if (gristAmount > 0)
                    this.world.spawnEntity(new EntityGrist(world, randX(), this.posY, randZ(), new GristAmount(gristType.getType(), gristAmount)));
            }
        }
        if (this.rand.nextInt(4) == 0)
            this.world.spawnEntity(new EntityVitalityGel(world, randX(), this.posY, randZ(), this.getVitalityGel()));
    }
}
Also used : GristSet(com.mraof.minestuck.util.GristSet) EntityGrist(com.mraof.minestuck.entity.item.EntityGrist) EntityVitalityGel(com.mraof.minestuck.entity.item.EntityVitalityGel) GristAmount(com.mraof.minestuck.util.GristAmount) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityGrist (com.mraof.minestuck.entity.item.EntityGrist)2 ItemStack (net.minecraft.item.ItemStack)2 EntityVitalityGel (com.mraof.minestuck.entity.item.EntityVitalityGel)1 GristAmount (com.mraof.minestuck.util.GristAmount)1 GristSet (com.mraof.minestuck.util.GristSet)1 EntityItem (net.minecraft.entity.item.EntityItem)1