-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite remaining Fabric platform code in Java
- Loading branch information
Showing
46 changed files
with
791 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package juuxel.adorn.item; | ||
|
||
import juuxel.adorn.block.AdornBlocks; | ||
import juuxel.adorn.lib.AdornTags; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemConvertible; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.registry.tag.TagKey; | ||
|
||
import java.util.Set; | ||
|
||
public sealed interface FuelData { | ||
Set<FuelData> FUEL_DATA = Set.of( | ||
// Wooden (300) | ||
new ForTag(AdornTags.CHAIRS.item(), 300), | ||
new ForTag(AdornTags.DRAWERS.item(), 300), | ||
new ForTag(AdornTags.TABLES.item(), 300), | ||
new ForTag(AdornTags.BENCHES.item(), 300), | ||
new ForTag(AdornTags.WOODEN_POSTS.item(), 300), | ||
new ForTag(AdornTags.WOODEN_PLATFORMS.item(), 300), | ||
new ForTag(AdornTags.WOODEN_STEPS.item(), 300), | ||
new ForTag(AdornTags.WOODEN_SHELVES.item(), 300), | ||
new ForItem(AdornBlocks.INSTANCE.getCRATE(), 300), | ||
// Woollen (150) | ||
new ForTag(AdornTags.SOFAS.item(), 150) | ||
); | ||
|
||
int burnTime(); | ||
boolean matches(ItemStack stack); | ||
|
||
record ForItem(ItemConvertible item, int burnTime) implements FuelData { | ||
@Override | ||
public boolean matches(ItemStack stack) { | ||
return stack.isOf(item.asItem()); | ||
} | ||
} | ||
|
||
record ForTag(TagKey<Item> tag, int burnTime) implements FuelData { | ||
@Override | ||
public boolean matches(ItemStack stack) { | ||
return stack.isIn(tag); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package juuxel.adorn; | ||
|
||
import juuxel.adorn.block.AdornBlockEntities; | ||
import juuxel.adorn.block.AdornBlocks; | ||
import juuxel.adorn.block.variant.BlockVariantSets; | ||
import juuxel.adorn.client.ClientEvents; | ||
import juuxel.adorn.client.gui.screen.AdornMenuScreens; | ||
import juuxel.adorn.compat.Compat; | ||
import juuxel.adorn.config.ConfigManager; | ||
import juuxel.adorn.criterion.AdornCriteria; | ||
import juuxel.adorn.entity.AdornEntities; | ||
import juuxel.adorn.item.AdornItems; | ||
import juuxel.adorn.item.group.AdornItemGroups; | ||
import juuxel.adorn.lib.AdornBlocksFabric; | ||
import juuxel.adorn.lib.AdornEntitiesFabric; | ||
import juuxel.adorn.lib.AdornGameRules; | ||
import juuxel.adorn.lib.AdornItemsFabric; | ||
import juuxel.adorn.lib.AdornNetworking; | ||
import juuxel.adorn.lib.AdornSounds; | ||
import juuxel.adorn.lib.AdornStats; | ||
import juuxel.adorn.lib.AdornTags; | ||
import juuxel.adorn.lib.SofaSleeping; | ||
import juuxel.adorn.loot.AdornLootConditionTypes; | ||
import juuxel.adorn.loot.AdornLootFunctionTypes; | ||
import juuxel.adorn.menu.AdornMenus; | ||
import juuxel.adorn.recipe.AdornRecipes; | ||
import juuxel.adorn.resources.AdornResources; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
public final class Adorn { | ||
public static void init() { | ||
ConfigManager.get().init(); | ||
AdornSounds.init(); | ||
AdornBlocks.init(); | ||
AdornBlocksFabric.init(); | ||
AdornBlockEntities.init(); | ||
AdornItems.init(); | ||
AdornItemsFabric.init(); | ||
AdornItemGroups.init(); | ||
AdornEntities.init(); | ||
AdornMenus.init(); | ||
AdornNetworking.init(); | ||
AdornTags.init(); | ||
AdornGameRules.init(); | ||
AdornStats.init(); | ||
SofaSleeping.init(); | ||
AdornCriteria.init(); | ||
AdornRecipes.init(); | ||
AdornLootConditionTypes.init(); | ||
AdornLootFunctionTypes.init(); | ||
Compat.init(); | ||
BlockVariantSets.register(); | ||
AdornBlocksFabric.afterRegister(); | ||
ConfigManager.get().finalize(); | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
public static void initClient() { | ||
AdornBlocksFabric.initClient(); | ||
AdornEntitiesFabric.initClient(); | ||
AdornMenuScreens.register(); | ||
AdornNetworking.initClient(); | ||
AdornResources.initClient(); | ||
ClientEvents.init(); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
fabric/src/main/java/juuxel/adorn/block/entity/BrewerBlockEntityFabric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package juuxel.adorn.block.entity; | ||
|
||
import com.google.common.base.Predicates; | ||
import juuxel.adorn.fluid.FluidReference; | ||
import juuxel.adorn.util.FluidStorageReference; | ||
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; | ||
import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; | ||
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class BrewerBlockEntityFabric extends BrewerBlockEntity { | ||
private static final String NBT_FLUID = "Fluid"; | ||
private static final String NBT_VOLUME = "Volume"; | ||
|
||
private final SingleVariantStorage<FluidVariant> fluidStorage = new SingleVariantStorage<FluidVariant>() { | ||
@Override | ||
protected long getCapacity(FluidVariant variant) { | ||
return FLUID_CAPACITY_IN_BUCKETS * FluidConstants.BUCKET; | ||
} | ||
|
||
@Override | ||
protected FluidVariant getBlankVariant() { | ||
return FluidVariant.blank(); | ||
} | ||
|
||
@Override | ||
protected void onFinalCommit() { | ||
markDirty(); | ||
} | ||
}; | ||
|
||
private final FluidReference fluidReference = new FluidStorageReference(fluidStorage); | ||
|
||
public BrewerBlockEntityFabric(BlockPos pos, BlockState state) { | ||
super(pos, state); | ||
} | ||
|
||
public SingleVariantStorage<FluidVariant> getFluidStorage() { | ||
return fluidStorage; | ||
} | ||
|
||
@Override | ||
public FluidReference getFluidReference() { | ||
return fluidReference; | ||
} | ||
|
||
@Override | ||
protected boolean canExtractFluidContainer() { | ||
try (var transaction = Transaction.openOuter()) { | ||
return extractFluidContainer(transaction) == 0L; | ||
} | ||
} | ||
|
||
@Override | ||
protected void tryExtractFluidContainer() { | ||
extractFluidContainer(null); | ||
} | ||
|
||
private long extractFluidContainer(@Nullable TransactionContext transaction) { | ||
var fluidContainerSlot = InventoryStorage.of(this, null).getSlot(FLUID_CONTAINER_SLOT); | ||
var itemStorage = FluidStorage.ITEM.find(getStack(FLUID_CONTAINER_SLOT), ContainerItemContext.ofSingleSlot(fluidContainerSlot)); | ||
return StorageUtil.move(itemStorage, fluidStorage, Predicates.alwaysTrue(), Long.MAX_VALUE, transaction); | ||
} | ||
|
||
@Override | ||
protected void writeNbt(NbtCompound nbt) { | ||
super.writeNbt(nbt); | ||
nbt.put(NBT_FLUID, fluidStorage.variant.toNbt()); | ||
nbt.putLong(NBT_VOLUME, fluidStorage.amount); | ||
} | ||
|
||
@Override | ||
public void readNbt(NbtCompound nbt) { | ||
super.readNbt(nbt); | ||
fluidStorage.variant = FluidVariant.fromNbt(nbt.getCompound(NBT_FLUID)); | ||
fluidStorage.amount = nbt.getLong(NBT_VOLUME); | ||
} | ||
} |
Oops, something went wrong.