use of net.minecraft.inventory.Inventory in project MiniUtilities by OneLemonyBoi.
the class MoltenHeadHandler method handleBlockBreak.
public static void handleBlockBreak(BreakEvent event) {
if (!event.getWorld().isRemote() && EnchantmentHelper.getEnchantmentLevel(EnchantmentList.MoltenHead.get(), event.getPlayer().getHeldItem(Hand.MAIN_HAND)) > 0) {
// Checks if running on server and enchant is on tool
// Casts IWorld to ServerWorld
ServerWorld serverWorld = ((ServerWorld) event.getWorld());
ItemStack pick = event.getPlayer().getHeldItem(Hand.MAIN_HAND);
int fortuneAmount = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, pick);
int silkTouchAmount = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, pick);
LootContext.Builder lootcontext$builder = (new LootContext.Builder(serverWorld).withRandom(serverWorld.rand).withParameter(LootParameters.ORIGIN, Vector3d.copyCentered(event.getPos())).withParameter(LootParameters.TOOL, // Makes lootcontext to calculate drops
pick));
// Calculates drops
List<ItemStack> drops = event.getState().getDrops(lootcontext$builder);
for (ItemStack item : drops) {
// Iteration
ItemStack stack = serverWorld.getRecipeManager().getRecipe(IRecipeType.SMELTING, new Inventory(item), serverWorld).map(FurnaceRecipe::getRecipeOutput).filter(itemStack -> !itemStack.isEmpty()).map(itemStack -> ItemHandlerHelper.copyStackWithSize(itemStack, item.getCount() * itemStack.getCount())).orElse(// Recipe as var
item);
if (fortuneAmount >= 1 && silkTouchAmount <= 0 && !stack.isItemEqual(item)) {
int addedCount = new Random().nextInt(fortuneAmount + 2) - 1;
if (addedCount < 0) {
addedCount = 0;
}
addedCount++;
stack.setCount(stack.getCount() * addedCount);
}
// Spawns Itemstack
InventoryHelper.spawnItemStack(event.getPlayer().world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), stack);
}
// Breaks block
event.getPlayer().world.destroyBlock(event.getPos(), false);
event.setResult(Event.Result.DENY);
}
}
use of net.minecraft.inventory.Inventory in project Capybara-Fabricated by ZestyBlaze.
the class CapybaraEntity method interactMob.
@Override
public ActionResult interactMob(PlayerEntity player, Hand hand) {
final ItemStack stack = player.getStackInHand(hand);
if (player.isSneaking()) {
if (stack.getItem() == Blocks.CHEST.asItem()) {
if (inventory == null || inventory.size() < 27) {
inventory = new SimpleInventory(27);
dataTracker.set(CHESTS, 1);
if (!player.getAbilities().creativeMode) {
stack.decrement(1);
}
return ActionResult.SUCCESS;
} else if (inventory.size() < 54) {
Inventory inv = new SimpleInventory(54);
for (int i = 0; i < 27; i++) {
inv.setStack(i, inventory.getStack(i));
}
inventory = inv;
dataTracker.set(CHESTS, 2);
if (!player.getAbilities().creativeMode) {
stack.decrement(1);
}
return ActionResult.SUCCESS;
}
}
if (stack.getItem() == Items.STICK) {
this.setSitting(!this.isSitting());
} else {
player.openHandledScreen(this);
return ActionResult.SUCCESS;
}
} else if (TEMPT_ITEMS.get().contains(stack.getItem()) && !isTamed()) {
if (this.random.nextInt(3) == 0) {
this.setOwner(player);
this.navigation.stop();
this.setTarget(null);
this.setSitting(true);
this.world.sendEntityStatus(this, (byte) 7);
}
if (!player.getAbilities().creativeMode) {
stack.decrement(1);
} else {
this.world.sendEntityStatus(this, (byte) 6);
}
return ActionResult.SUCCESS;
} else if (!this.hasPassengers() && !player.shouldCancelInteraction() && !this.isBaby() && !isInSittingPose()) {
boolean flag = this.isBreedingItem(player.getStackInHand(hand));
if (!flag && !this.hasPassengers() && !player.shouldCancelInteraction()) {
if (!this.world.isClient) {
player.startRiding(this);
}
return ActionResult.SUCCESS;
}
} else if (!this.getPassengerList().isEmpty()) {
removeAllPassengers();
}
return super.interactMob(player, hand);
}
use of net.minecraft.inventory.Inventory in project alaskanativecraft by Platymemo.
the class DryingRackBlockEntity method updateItemsBeingDried.
@SuppressWarnings("unused")
public static void updateItemsBeingDried(World world, BlockPos pos, BlockState state, @NotNull DryingRackBlockEntity dryingRackBlockEntity) {
for (int i = 0; i < dryingRackBlockEntity.itemsBeingDried.size(); ++i) {
ItemStack itemStack = dryingRackBlockEntity.itemsBeingDried.get(i);
if (!itemStack.isEmpty()) {
dryingRackBlockEntity.dryingTimes[i]++;
if (dryingRackBlockEntity.dryingTimes[i] >= dryingRackBlockEntity.dryingTotalTimes[i]) {
// Don't want it to keep counting up unnecessarily high
dryingRackBlockEntity.dryingTimes[i] = dryingRackBlockEntity.dryingTotalTimes[i];
Inventory inventory = new SimpleInventory(itemStack);
ItemStack itemStack2 = world.getRecipeManager().getFirstMatch(AlaskaRecipes.DRYING, inventory, world).map((dryingRecipe) -> dryingRecipe.craft(inventory)).orElse(itemStack);
dryingRackBlockEntity.itemsBeingDried.set(i, itemStack2);
dryingRackBlockEntity.updateListeners();
}
}
}
}
use of net.minecraft.inventory.Inventory in project Client by MatHax.
the class EChestMemory method onOpenScreenEvent.
@EventHandler
private static void onOpenScreenEvent(OpenScreenEvent event) {
if (echestOpenedState == 1 && event.screen instanceof GenericContainerScreen) {
echestOpenedState = 2;
return;
}
if (echestOpenedState == 0)
return;
if (!(mc.currentScreen instanceof GenericContainerScreen))
return;
GenericContainerScreenHandler container = ((GenericContainerScreen) mc.currentScreen).getScreenHandler();
if (container == null)
return;
Inventory inv = container.getInventory();
for (int i = 0; i < 27; i++) {
ITEMS.set(i, inv.getStack(i));
}
echestOpenedState = 0;
}
use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.
the class SkilletTileEntity method addItemToCook.
public ItemStack addItemToCook(ItemStack addedStack, @Nullable PlayerEntity player) {
Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(new Inventory(addedStack));
if (recipe.isPresent()) {
cookingTimeTotal = SkilletBlock.getSkilletCookingTime(recipe.get().getCookingTime(), fireAspectLevel);
boolean wasEmpty = getStoredStack().isEmpty();
ItemStack remainderStack = inventory.insertItem(0, addedStack.copy(), false);
if (!ItemStack.matches(remainderStack, addedStack)) {
lastRecipeID = recipe.get().getId();
cookingTime = 0;
if (wasEmpty && level != null && isHeated(level, worldPosition)) {
level.playSound(null, worldPosition.getX() + 0.5F, worldPosition.getY() + 0.5F, worldPosition.getZ() + 0.5F, ModSounds.BLOCK_SKILLET_ADD_FOOD.get(), SoundCategory.BLOCKS, 0.8F, 1.0F);
}
return remainderStack;
}
} else if (player != null) {
player.displayClientMessage(TextUtils.getTranslation("block.skillet.invalid_item"), true);
}
return addedStack;
}
Aggregations