Browse Source

Brewing stands

master
Martmists 2 years ago
parent
commit
3fa1e33321
  1. 6
      compat/1.16/build.gradle
  2. 80
      src/main/java/com/martmists/ynet/mixin/providers/item/BrewingStandBlockMixin.java
  3. 4
      src/main/java/com/martmists/ynet/mixin/providers/item/GenericMachineBlockMixin.java
  4. 1
      versions/common.gradle

6
compat/1.16/build.gradle

@ -15,13 +15,12 @@ apply plugin: 'fabric-loom' @@ -15,13 +15,12 @@ apply plugin: 'fabric-loom'
apply plugin: 'java'
apply plugin: "idea"
setBuildDir("../../build")
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "com.github.vini2003:spinnery:${project.spinnery_version}"
include "com.github.vini2003:spinnery:${project.spinnery_version}"
}
repositories {
@ -34,3 +33,6 @@ repositories { @@ -34,3 +33,6 @@ repositories {
url 'https://jitpack.io'
}
}
setBuildDir("../../build")
archivesBaseName = "internal-compat-${project.name}"

80
src/main/java/com/martmists/ynet/mixin/providers/item/BrewingStandBlockMixin.java

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
package com.martmists.ynet.mixin.providers.item;
import com.martmists.ynet.api.ItemProvider;
import net.minecraft.block.BrewingStandBlock;
import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import java.util.ArrayList;
import java.util.List;
@Mixin(BrewingStandBlock.class)
public class BrewingStandBlockMixin implements ItemProvider {
// Potions: Slot 0-2
// Ingredient: Slot 3
// Blaze powder: Slot 4
@Override
public int getItemInputCount(BlockView world, BlockPos pos, ItemStack itemStack) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
int totalInsertable = 0;
for (int i = 0; i < 5; i++) {
if (be.canInsertInvStack(i, itemStack, null)) {
ItemStack stack = be.getInvStack(i);
totalInsertable += stack.getMaxCount() - stack.getCount();
}
}
return Math.min(totalInsertable, itemStack.getCount());
}
@Override
public void inputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
int totalInserted = 0;
for (int i = 0; i < 5; i++) {
if (be.canInsertInvStack(i, itemStack, null)) {
ItemStack stack = be.getInvStack(i);
int insertible = Math.min(stack.getMaxCount() - stack.getCount(), itemStack.getCount() - totalInserted);
stack.setCount(stack.getCount() + insertible);
totalInserted += insertible;
}
}
}
@Override
public ItemStack[] getItemOutputStacks(BlockView world, BlockPos pos) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
List<ItemStack> stacks = new ArrayList<>();
for (int i = 0; i < 5; i++) {
ItemStack stack = be.getInvStack(i);
if (be.canExtractInvStack(i, stack, null)) {
stacks.add(stack);
}
}
return stacks.toArray(new ItemStack[0]);
}
@Override
public void outputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
int totalExtracted = 0;
for (int i = 0; i < 5; i++) {
if (be.canExtractInvStack(i, itemStack, null)) {
ItemStack stack = be.getInvStack(i);
int extractable = Math.min(stack.getCount(), itemStack.getCount() - totalExtracted);
stack.setCount(stack.getCount() - extractable);
totalExtracted += extractable;
}
}
}
private BrewingStandBlockEntity getBlockEntity(BlockView world, BlockPos pos) {
return (BrewingStandBlockEntity) world.getBlockEntity(pos);
}
}

4
src/main/java/com/martmists/ynet/mixin/providers/item/GenericMachineBlockMixin.java

@ -83,10 +83,6 @@ public class GenericMachineBlockMixin implements ItemProvider { @@ -83,10 +83,6 @@ public class GenericMachineBlockMixin implements ItemProvider {
return;
}
}
if (stack.isEmpty()) {
stacks.set(i, new ItemStack(itemStack.getItem(), outputCount));
return;
}
i++;
}
}

1
versions/common.gradle

@ -19,6 +19,7 @@ dependencies { @@ -19,6 +19,7 @@ dependencies {
}
modImplementation "com.github.vini2003:spinnery:${project.spinnery_version}"
include "com.github.vini2003:spinnery:${project.spinnery_version}"
}
repositories {

Loading…
Cancel
Save