Skip to content

Commit

Permalink
BrewingKeg comparator + hopper interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
MEGATREX4 committed Aug 10, 2024
1 parent b385972 commit ad57fee
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.megatrex4.ukrainian_dlight.block.entity.ModBlockEntities;
//import com.megatrex4.ukrainian_dlight.compat.patchouli.CustomBrewingRecipeProcessor;
import com.megatrex4.ukrainian_dlight.config.ModConfig;
import com.megatrex4.ukrainian_dlight.initialize.Initialise;
import com.megatrex4.ukrainian_dlight.initialize.CustomizeLootTables;
import com.megatrex4.ukrainian_dlight.item.ModItemGroups;
import com.megatrex4.ukrainian_dlight.item.ModItems;
import com.megatrex4.ukrainian_dlight.item.ToolTipHelper;
Expand All @@ -15,9 +15,7 @@
import com.megatrex4.ukrainian_dlight.screen.ModScreenHandlers;
import com.megatrex4.ukrainian_dlight.screen.ModScreens;
import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.MutableText;
Expand Down Expand Up @@ -53,7 +51,7 @@ public void onInitialize() {
ModRecipes.registerRecipes();
ModScreens.registerScreens();
ModConfig.loadConfig();
Initialise.register();
CustomizeLootTables.register();

LOGGER.info("Hello Fabric world it's " + MOD_ID + "!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
Expand Down Expand Up @@ -186,13 +187,11 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
// Save BlockEntity data to NBT
NbtCompound tag = new NbtCompound();
brewingKegEntity.writeNbt(tag);
System.out.println("Saved BlockEntityTag: " + tag.toString()); // Debug line
itemStack.setSubNbt("BlockEntityTag", tag);

// Save DisplaySlot to NBT
NbtCompound displaySlotTag = new NbtCompound();
brewingKegEntity.getStack(DRINKS_DISPLAY_SLOT).writeNbt(displaySlotTag);
System.out.println("Saved DisplaySlot: " + displaySlotTag.toString()); // Debug line
itemStack.setSubNbt("DisplaySlot", displaySlotTag);

// Spawn the item entity with the BlockEntityTag and DisplaySlot NBT
Expand All @@ -204,7 +203,6 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
}
}


public static void spawnParticles(World world, BlockPos pos, BlockState state) {
Random random = world.random;
if (world != null) {
Expand All @@ -220,7 +218,6 @@ public static void spawnParticles(World world, BlockPos pos, BlockState state) {
}
}


@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack heldStack = player.getStackInHand(hand);
Expand Down Expand Up @@ -258,9 +255,6 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return ActionResult.SUCCESS;
}




private boolean giveItemToPlayerOrDrop(World world, PlayerEntity player, ItemStack itemStack) {
if (!player.getInventory().insertStack(itemStack)) {
ItemEntity itemEntity = new ItemEntity(world, player.getX(), player.getY(), player.getZ(), itemStack);
Expand All @@ -284,4 +278,17 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block
FACING = Properties.HORIZONTAL_FACING;
}

@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}

@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof BrewingKegBlockEntity) {
return ((BrewingKegBlockEntity) blockEntity).calculateComparatorOutput();
}
return super.getComparatorOutput(state, world, pos);
}
}
Loading

0 comments on commit ad57fee

Please sign in to comment.