Moved save logic inside the 1.20 branch, as they don't compile without errors on 1.21
Change hybridizer logic to no longer require a catalyst fix brachiosaurus_dna.png Fix flame texture on generator for 1.21 Adds power handling for machines in NF 1.21 Adds power handling to fabric Actually fix screen registration for Fabric 1.20
This commit is contained in:
@@ -111,24 +111,6 @@ public class CommonClientClass {
|
||||
EntityRendererRegistry.register(ModEntities.TROODON, TroodonRenderer::new);
|
||||
EntityRendererRegistry.register(ModEntities.UTAHRAPTOR, UtahraptorRenderer::new);
|
||||
|
||||
//? if <=1.20.1 {
|
||||
ClientLifecycleEvent.CLIENT_SETUP.register(minecraft -> {
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.GENERATOR_MENU.get(), GeneratorScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.DNA_EXTRACTOR_MENU.get(), DNAExtractorScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.DNA_ANALYZER_MENU.get(), DNAAnalyzerScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.FOSSIL_GRINDER_MENU.get(), FossilGrinderScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.FOSSIL_CLEANER_MENU.get(), FossilCleanerScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.DNA_HYBRIDIZER_MENU.get(), DNAHybridizerScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.EMBRYONIC_MACHINE_MENU.get(), EmbryonicMachineScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.EMBRYO_CALCIFICATION_MACHINE_MENU.get(), EmbryoCalcificationMachineScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.INCUBATOR_MENU.get(), IncubatorScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.TANK_MENU.get(), TankScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.POWER_CELL_MENU.get(), PowerCellScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.WOOD_CRATE_MENU.get(), CrateScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.IRON_CRATE_MENU.get(), CrateScreen::new);
|
||||
});
|
||||
//?}
|
||||
|
||||
if (Platform.isFabric()) {
|
||||
registerSpawnEggColors();
|
||||
registerRenderTypes();
|
||||
@@ -142,6 +124,24 @@ public class CommonClientClass {
|
||||
});
|
||||
}
|
||||
|
||||
//? if <=1.20.1 {
|
||||
public static void registerScreens() {
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.GENERATOR_MENU.get(), GeneratorScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.DNA_EXTRACTOR_MENU.get(), DNAExtractorScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.DNA_ANALYZER_MENU.get(), DNAAnalyzerScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.FOSSIL_GRINDER_MENU.get(), FossilGrinderScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.FOSSIL_CLEANER_MENU.get(), FossilCleanerScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.DNA_HYBRIDIZER_MENU.get(), DNAHybridizerScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.EMBRYONIC_MACHINE_MENU.get(), EmbryonicMachineScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.EMBRYO_CALCIFICATION_MACHINE_MENU.get(), EmbryoCalcificationMachineScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.INCUBATOR_MENU.get(), IncubatorScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.TANK_MENU.get(), TankScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.POWER_CELL_MENU.get(), PowerCellScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.WOOD_CRATE_MENU.get(), CrateScreen::new);
|
||||
MenuRegistry.registerScreenFactory(ModMenuTypes.IRON_CRATE_MENU.get(), CrateScreen::new);
|
||||
}
|
||||
//?}
|
||||
|
||||
private static void registerSpawnEggColors() {
|
||||
ModItems.ITEMS.forEach(itemSupplier -> {
|
||||
Item item = itemSupplier.get();
|
||||
|
||||
@@ -677,7 +677,16 @@ public class ModBlocks {
|
||||
}
|
||||
|
||||
private static <T extends Block> void registerBlockItem(String name, RegistrySupplier<T> block) {
|
||||
ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties()));
|
||||
ModItems.ITEMS.register(name, () -> {
|
||||
T blockInstance = block.get();
|
||||
Item.Properties properties = new Item.Properties();
|
||||
|
||||
if (blockInstance instanceof EggBlock || blockInstance instanceof IncubatedEggBlock) {
|
||||
properties.stacksTo(1);
|
||||
}
|
||||
|
||||
return new BlockItem(blockInstance, properties);
|
||||
});
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
|
||||
+31
-2
@@ -138,7 +138,7 @@ public class DNAAnalyzerBlockEntity extends BlockEntity implements ExtendedMenuP
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
tag.putInt("Prog", this.progress);
|
||||
tag.putInt("MaxProg", this.maxProgress);
|
||||
tag.put("Energy", energyStorage.saveNBT());
|
||||
@@ -147,13 +147,42 @@ public class DNAAnalyzerBlockEntity extends BlockEntity implements ExtendedMenuP
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
progress = tag.getInt("Prog");
|
||||
maxProgress = tag.getInt("MaxProg");
|
||||
if (tag.contains("Energy")) {
|
||||
energyStorage.loadNBT(tag.getCompound("Energy"));
|
||||
}
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+29
-2
@@ -138,7 +138,7 @@ public class DNAExtractorBlockEntity extends BlockEntity implements ExtendedMenu
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
tag.putInt("Prog", this.progress);
|
||||
tag.putInt("MaxProg", this.maxProgress);
|
||||
tag.put("Energy", energyStorage.saveNBT());
|
||||
@@ -147,13 +147,40 @@ public class DNAExtractorBlockEntity extends BlockEntity implements ExtendedMenu
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
progress = tag.getInt("Prog");
|
||||
maxProgress = tag.getInt("MaxProg");
|
||||
if (tag.contains("Energy")) {
|
||||
energyStorage.loadNBT(tag.getCompound("Energy"));
|
||||
}
|
||||
}private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+29
-2
@@ -138,16 +138,43 @@ public class DNAHybridizerBlockEntity extends BlockEntity implements ExtendedMen
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
saveCommonData(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
loadCommonData(tag);
|
||||
}private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+31
-2
@@ -135,16 +135,45 @@ public class EmbryoCalcificationMachineBlockEntity extends BlockEntity implement
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
saveCommonData(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
loadCommonData(tag);
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+31
-2
@@ -139,16 +139,45 @@ public class EmbryonicMachineBlockEntity extends BlockEntity implements Extended
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
saveCommonData(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
loadCommonData(tag);
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+31
-2
@@ -151,7 +151,7 @@ public class FossilCleanerBlockEntity extends BlockEntity implements ExtendedMen
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
tag.putInt("Prog", this.progress);
|
||||
tag.putInt("MaxProg", this.maxProgress);
|
||||
tag.put("Energy", energyStorage.saveNBT());
|
||||
@@ -163,7 +163,7 @@ public class FossilCleanerBlockEntity extends BlockEntity implements ExtendedMen
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
progress = tag.getInt("Prog");
|
||||
maxProgress = tag.getInt("MaxProg");
|
||||
if (tag.contains("Energy")) energyStorage.loadNBT(tag.getCompound("Energy"));
|
||||
@@ -178,6 +178,35 @@ public class FossilCleanerBlockEntity extends BlockEntity implements ExtendedMen
|
||||
fluidStack = FluidStack.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+31
-2
@@ -135,16 +135,45 @@ public class FossilGrinderBlockEntity extends BlockEntity implements ExtendedMen
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
saveCommonData(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
loadCommonData(tag);
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+31
-2
@@ -136,7 +136,7 @@ public class IncubatorBlockEntity extends BlockEntity implements ExtendedMenuPro
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
tag.put("Inventory", itemHandler.createTag(registries));
|
||||
tag.put("Inventory", saveInventory(registries));
|
||||
tag.putInt("Prog0", this.progress[0]);
|
||||
tag.putInt("Prog1", this.progress[1]);
|
||||
tag.putInt("Prog2", this.progress[2]);
|
||||
@@ -149,7 +149,7 @@ public class IncubatorBlockEntity extends BlockEntity implements ExtendedMenuPro
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
itemHandler.fromTag(tag.getList("Inventory", 10), registries);
|
||||
loadInventory(tag.getList("Inventory", 10), registries);
|
||||
if (tag.contains("Energy")) {
|
||||
energyStorage.loadNBT(tag.getCompound("Energy"));
|
||||
}
|
||||
@@ -160,6 +160,35 @@ public class IncubatorBlockEntity extends BlockEntity implements ExtendedMenuPro
|
||||
maxProgress[1] = tag.getInt("Max1");
|
||||
maxProgress[2] = tag.getInt("Max2");
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag) {
|
||||
|
||||
+31
-2
@@ -270,7 +270,7 @@ public class TankBlockEntity extends BlockEntity implements ExtendedMenuProvider
|
||||
/*@Override
|
||||
protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) {
|
||||
super.saveAdditional(pTag, pRegistries);
|
||||
pTag.put("Inventory", itemHandler.createTag(pRegistries));
|
||||
pTag.put("Inventory", saveInventory(pRegistries));
|
||||
if (!fluidStack.isEmpty()) {
|
||||
pTag.put("Fluid", fluidStack.write(pRegistries, new CompoundTag()));
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public class TankBlockEntity extends BlockEntity implements ExtendedMenuProvider
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) {
|
||||
super.loadAdditional(pTag, pRegistries);
|
||||
itemHandler.fromTag(pTag.getList("Inventory", 10), pRegistries);
|
||||
loadInventory(pTag.getList("Inventory", 10), pRegistries);
|
||||
if (pTag.contains("Fluid", 10)) {
|
||||
CompoundTag fluidTag = pTag.getCompound("Fluid");
|
||||
if (fluidTag.contains("id") && fluidTag.contains("amount")) {
|
||||
@@ -291,6 +291,35 @@ public class TankBlockEntity extends BlockEntity implements ExtendedMenuProvider
|
||||
this.fluidStack = FluidStack.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private ListTag saveInventory(HolderLookup.Provider registries) {
|
||||
ListTag listTag = new ListTag();
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getContainerSize(); slot++) {
|
||||
ItemStack stack = itemHandler.getItem(slot);
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag stackTag = new CompoundTag();
|
||||
stackTag.putByte("Slot", (byte) slot);
|
||||
listTag.add(stack.save(registries, stackTag));
|
||||
}
|
||||
}
|
||||
|
||||
return listTag;
|
||||
}
|
||||
|
||||
private void loadInventory(ListTag listTag, HolderLookup.Provider registries) {
|
||||
itemHandler.clearContent();
|
||||
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag stackTag = listTag.getCompound(i);
|
||||
int slot = stackTag.getByte("Slot") & 255;
|
||||
|
||||
if (slot >= 0 && slot < itemHandler.getContainerSize()) {
|
||||
itemHandler.setItem(slot, ItemStack.parseOptional(registries, stackTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*///?} else {
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag pTag) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ModRecipeProvider {
|
||||
// Custom
|
||||
void dnaExtracting(ItemLike testTube, ItemLike tissue, ItemLike dna, int count);
|
||||
void dnaAnalyzing(ItemLike testTube, ItemLike material, ItemLike dna, int count);
|
||||
void dnaHybridizing(ItemLike result, int count, ItemLike catalyst, ItemLike... ingredients);
|
||||
void dnaHybridizing(ItemLike result, int count, ItemLike... ingredients);
|
||||
void embryonicMachine(ItemLike syringe, ItemLike dna, ItemLike catalyst, ItemLike result, int count);
|
||||
void embryoCalcification(ItemLike syringe, ItemLike egg, ItemLike result, int count);
|
||||
void incubating(ItemLike egg, ItemLike result, int count);
|
||||
@@ -345,24 +345,21 @@ public class ModRecipeProvider {
|
||||
|
||||
helper.dnaAnalyzing(ModItems.TEST_TUBE.get(), ModItems.FROG_MATERIAL.get(), ModItems.FROG_DNA.get(), 1);
|
||||
|
||||
|
||||
helper.dnaHybridizing(ModItems.INDOMINUS_REX_DNA.get(), 1, ModItems.FROG_DNA.get(),
|
||||
ModItems.TYRANNOSAURUS_REX_DNA.get(),
|
||||
ModItems.VELOCIRAPTOR_DNA.get(),
|
||||
ModItems.CARNOTAURUS_DNA.get(),
|
||||
ModItems.THERIZINOSAURUS_DNA.get(),
|
||||
ModItems.MAJUNGASAURUS_DNA.get(),
|
||||
ModItems.RUGOPS_DNA.get(),
|
||||
ModItems.GIGANOTOSAURUS_DNA.get());
|
||||
|
||||
helper.dnaHybridizing(ModItems.DISTORTUS_REX_DNA.get(), 1, ModItems.FROG_DNA.get(),
|
||||
ModItems.TYRANNOSAURUS_REX_DNA.get(),
|
||||
ModItems.BRACHIOSAURUS_DNA.get(),
|
||||
ModItems.VELOCIRAPTOR_DNA.get());
|
||||
|
||||
helper.dnaHybridizing(ModItems.INDORAPTOR_DNA.get(), 1, ModItems.FROG_DNA.get(),
|
||||
ModItems.INDOMINUS_REX_DNA.get(),
|
||||
ModItems.VELOCIRAPTOR_DNA.get());
|
||||
helper.dnaHybridizing(ModItems.INDOMINUS_REX_DNA.get(), 1,
|
||||
ModItems.TYRANNOSAURUS_REX_DNA.get(),
|
||||
ModItems.VELOCIRAPTOR_DNA.get(),
|
||||
ModItems.CARNOTAURUS_DNA.get(),
|
||||
ModItems.THERIZINOSAURUS_DNA.get(),
|
||||
ModItems.MAJUNGASAURUS_DNA.get(),
|
||||
ModItems.RUGOPS_DNA.get(),
|
||||
ModItems.GIGANOTOSAURUS_DNA.get());
|
||||
helper.dnaHybridizing(ModItems.DISTORTUS_REX_DNA.get(), 1,
|
||||
ModItems.TYRANNOSAURUS_REX_DNA.get(),
|
||||
ModItems.BRACHIOSAURUS_DNA.get(),
|
||||
ModItems.VELOCIRAPTOR_DNA.get());
|
||||
helper.dnaHybridizing(ModItems.INDORAPTOR_DNA.get(), 1,
|
||||
ModItems.INDOMINUS_REX_DNA.get(),
|
||||
ModItems.VELOCIRAPTOR_DNA.get());
|
||||
|
||||
helper.embryonicMachine(ModItems.SYRINGE.get(), ModItems.APATOSAURUS_DNA.get(), ModItems.FROG_DNA.get(), ModItems.APATOSAURUS_SYRINGE.get(), 1);
|
||||
helper.embryonicMachine(ModItems.SYRINGE.get(), ModItems.ALBERTOSAURUS_DNA.get(), ModItems.FROG_DNA.get(), ModItems.ALBERTOSAURUS_SYRINGE.get(), 1);
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package net.cmr.jurassicrevived.datagen.custom;
|
||||
|
||||
import net.cmr.jurassicrevived.Constants;
|
||||
import net.cmr.jurassicrevived.recipe.DNAAnalyzerRecipe;
|
||||
import net.minecraft.advancements.*;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
@@ -77,7 +78,7 @@ public class DNAAnalyzingRecipeBuilder {
|
||||
inputs.add(Ingredient.of(secondItem.orElseThrow()));
|
||||
ItemStack result = new ItemStack(resultItem.orElseThrow(), this.count);
|
||||
|
||||
DNAAnalyzerRecipe recipe = new DNAAnalyzerRecipe(inputs, result, Map.copyOf(this.weights));
|
||||
DNAAnalyzerRecipe recipe = new DNAAnalyzerRecipe(Constants.rl("dna_analyzer"), inputs, result, Map.copyOf(this.weights));
|
||||
|
||||
AdvancementHolder advancementHolder = null;
|
||||
if (!this.criteria.isEmpty()) {
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package net.cmr.jurassicrevived.datagen.custom;
|
||||
|
||||
import net.cmr.jurassicrevived.Constants;
|
||||
import net.cmr.jurassicrevived.recipe.DNAExtractorRecipe;
|
||||
import net.minecraft.advancements.*;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
@@ -77,7 +78,7 @@ public class DNAExtractingRecipeBuilder {
|
||||
inputs.add(Ingredient.of(secondItem.orElseThrow()));
|
||||
ItemStack result = new ItemStack(resultItem.orElseThrow(), this.count);
|
||||
|
||||
DNAExtractorRecipe recipe = new DNAExtractorRecipe(inputs, result, java.util.Map.copyOf(this.weights));
|
||||
DNAExtractorRecipe recipe = new DNAExtractorRecipe(Constants.rl("dna_extractor"), inputs, result, java.util.Map.copyOf(this.weights));
|
||||
|
||||
AdvancementHolder advancementHolder = null;
|
||||
if (!this.criteria.isEmpty()) {
|
||||
|
||||
+6
-33
@@ -1,5 +1,6 @@
|
||||
package net.cmr.jurassicrevived.datagen.custom;
|
||||
|
||||
import net.cmr.jurassicrevived.Constants;
|
||||
import net.cmr.jurassicrevived.recipe.DNAHybridizerRecipe;
|
||||
import net.minecraft.advancements.*;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
@@ -38,7 +39,6 @@ public class DNAHybridizingRecipeBuilder {
|
||||
private final Map<String, InventoryChangeTrigger.TriggerInstance> criteria;
|
||||
//?}
|
||||
private final NonNullList<Ingredient> ingredients = NonNullList.create();
|
||||
private java.util.Optional<ItemLike> catalyst = java.util.Optional.empty();
|
||||
|
||||
public DNAHybridizingRecipeBuilder(ItemLike result, int count) {
|
||||
this.resultItem = java.util.Optional.of(result.asItem());
|
||||
@@ -51,26 +51,21 @@ public class DNAHybridizingRecipeBuilder {
|
||||
}
|
||||
|
||||
public DNAHybridizingRecipeBuilder addIngredient(ItemLike item) {
|
||||
if (this.ingredients.size() >= 9) {
|
||||
throw new IllegalStateException("DNAHybridizer supports at most 9 input ingredients");
|
||||
if (this.ingredients.size() >= 8) {
|
||||
throw new IllegalStateException("DNAHybridizer supports at most 8 input ingredients");
|
||||
}
|
||||
this.ingredients.add(Ingredient.of(item));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DNAHybridizingRecipeBuilder addIngredient(Ingredient ingredient) {
|
||||
if (this.ingredients.size() >= 9) {
|
||||
throw new IllegalStateException("DNAHybridizer supports at most 9 input ingredients");
|
||||
if (this.ingredients.size() >= 8) {
|
||||
throw new IllegalStateException("DNAHybridizer supports at most 8 input ingredients");
|
||||
}
|
||||
this.ingredients.add(ingredient);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DNAHybridizingRecipeBuilder setCatalyst(ItemLike item) {
|
||||
this.catalyst = java.util.Optional.of(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
//? if >1.20.1 {
|
||||
/*public void save(RecipeOutput output) {
|
||||
ResourceLocation resultKey = BuiltInRegistries.ITEM.getKey(this.resultItem.orElseThrow());
|
||||
@@ -88,20 +83,9 @@ public class DNAHybridizingRecipeBuilder {
|
||||
NonNullList<Ingredient> inputs = NonNullList.create();
|
||||
inputs.addAll(this.ingredients);
|
||||
|
||||
if (inputs.size() > 8 && catalyst.isPresent()) {
|
||||
throw new IllegalStateException("When a catalyst is set, at most 8 regular ingredients are allowed (slot 9 is reserved).");
|
||||
}
|
||||
|
||||
if (catalyst.isPresent()) {
|
||||
while (inputs.size() < 8) {
|
||||
inputs.add(Ingredient.EMPTY);
|
||||
}
|
||||
inputs.add(Ingredient.of(catalyst.get()));
|
||||
}
|
||||
|
||||
ItemStack result = new ItemStack(resultItem.orElseThrow(), this.count);
|
||||
|
||||
DNAHybridizerRecipe recipe = new DNAHybridizerRecipe(inputs, result);
|
||||
DNAHybridizerRecipe recipe = new DNAHybridizerRecipe(Constants.rl("dna_hybridizer"), inputs, result);
|
||||
|
||||
AdvancementHolder advancementHolder = null;
|
||||
if (!this.criteria.isEmpty()) {
|
||||
@@ -133,17 +117,6 @@ public class DNAHybridizingRecipeBuilder {
|
||||
NonNullList<Ingredient> inputs = NonNullList.create();
|
||||
inputs.addAll(this.ingredients);
|
||||
|
||||
if (inputs.size() > 8 && catalyst.isPresent()) {
|
||||
throw new IllegalStateException("When a catalyst is set, at most 8 regular ingredients are allowed (slot 9 is reserved).");
|
||||
}
|
||||
|
||||
if (catalyst.isPresent()) {
|
||||
while (inputs.size() < 8) {
|
||||
inputs.add(Ingredient.EMPTY);
|
||||
}
|
||||
inputs.add(Ingredient.of(catalyst.get()));
|
||||
}
|
||||
|
||||
Advancement.Builder advancementBuilder = Advancement.Builder.advancement();
|
||||
advancementBuilder.parent(new ResourceLocation("recipes/root"))
|
||||
.addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(recipeId))
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package net.cmr.jurassicrevived.datagen.custom;
|
||||
|
||||
import net.cmr.jurassicrevived.Constants;
|
||||
import net.cmr.jurassicrevived.recipe.EmbryoCalcificationMachineRecipe;
|
||||
import net.minecraft.advancements.*;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
@@ -64,7 +65,7 @@ public class EmbryoCalcificationMachiningRecipeBuilder {
|
||||
inputs.add(Ingredient.of(secondItem.orElseThrow()));
|
||||
ItemStack result = new ItemStack(resultItem.orElseThrow(), this.count);
|
||||
|
||||
EmbryoCalcificationMachineRecipe recipe = new EmbryoCalcificationMachineRecipe(inputs, result);
|
||||
EmbryoCalcificationMachineRecipe recipe = new EmbryoCalcificationMachineRecipe(Constants.rl("embryo_calcification_machine"), inputs, result);
|
||||
|
||||
AdvancementHolder advancementHolder = null;
|
||||
if (!this.criteria.isEmpty()) {
|
||||
|
||||
@@ -14,7 +14,5 @@ public class MixinMinecraft
|
||||
@Inject(at = @At("TAIL"), method = "<init>")
|
||||
private void init(CallbackInfo info) {
|
||||
|
||||
Constants.LOG.info("This line is printed by an example mod common mixin!");
|
||||
Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType());
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public record DNAAnalyzerRecipe(
|
||||
).forGetter(DNAAnalyzerRecipe::inputs),
|
||||
ItemStack.CODEC.fieldOf("result").forGetter(DNAAnalyzerRecipe::output),
|
||||
Codec.unboundedMap(ResourceLocation.CODEC, Codec.INT).optionalFieldOf("weights", java.util.Map.of()).forGetter(DNAAnalyzerRecipe::weights)
|
||||
).apply(inst, DNAAnalyzerRecipe::new));
|
||||
).apply(inst, (inputs, output, weights) -> new DNAAnalyzerRecipe(Constants.rl("dna_analyzer"), inputs, output, weights)));
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, DNAAnalyzerRecipe> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, r) -> {
|
||||
@@ -114,7 +114,13 @@ public record DNAAnalyzerRecipe(
|
||||
int size = buf.readVarInt();
|
||||
NonNullList<Ingredient> ins = NonNullList.create();
|
||||
for(int i=0; i<size; i++) ins.add(Ingredient.CONTENTS_STREAM_CODEC.decode(buf));
|
||||
return new DNAAnalyzerRecipe(ins, ItemStack.STREAM_CODEC.decode(buf), buf.readMap(m -> new java.util.HashMap<>(), ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT));
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
java.util.Map<ResourceLocation, Integer> weights = buf.readMap(
|
||||
java.util.HashMap<ResourceLocation, Integer>::new,
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
ByteBufCodecs.VAR_INT
|
||||
);
|
||||
return new DNAAnalyzerRecipe(Constants.rl("dna_analyzer"), ins, output, weights);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public record DNAExtractorRecipe(
|
||||
).forGetter(DNAExtractorRecipe::inputs),
|
||||
ItemStack.CODEC.fieldOf("result").forGetter(DNAExtractorRecipe::output),
|
||||
Codec.unboundedMap(ResourceLocation.CODEC, Codec.INT).optionalFieldOf("weights", java.util.Map.of()).forGetter(DNAExtractorRecipe::weights)
|
||||
).apply(inst, DNAExtractorRecipe::new));
|
||||
).apply(inst, (inputs, output, weights) -> new DNAExtractorRecipe(Constants.rl("dna_extractor"), inputs, output, weights)));
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, DNAExtractorRecipe> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, r) -> {
|
||||
@@ -121,7 +121,13 @@ public record DNAExtractorRecipe(
|
||||
int size = buf.readVarInt();
|
||||
NonNullList<Ingredient> ins = NonNullList.create();
|
||||
for(int i=0; i<size; i++) ins.add(Ingredient.CONTENTS_STREAM_CODEC.decode(buf));
|
||||
return new DNAExtractorRecipe(ins, ItemStack.STREAM_CODEC.decode(buf), buf.readMap(m -> new java.util.HashMap<>(), ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT));
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
java.util.Map<ResourceLocation, Integer> weights = buf.readMap(
|
||||
java.util.HashMap<ResourceLocation, Integer>::new,
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
ByteBufCodecs.VAR_INT
|
||||
);
|
||||
return new DNAExtractorRecipe(Constants.rl("dna_extractor"), ins, output, weights);
|
||||
}
|
||||
);
|
||||
@Override public MapCodec<DNAExtractorRecipe> codec() { return CODEC; }
|
||||
|
||||
@@ -94,7 +94,7 @@ public record DNAHybridizerRecipe(ResourceLocation id, NonNullList<Ingredient> i
|
||||
l -> DataResult.success(List.copyOf(l))
|
||||
).forGetter(DNAHybridizerRecipe::inputs),
|
||||
ItemStack.CODEC.fieldOf("result").forGetter(DNAHybridizerRecipe::output)
|
||||
).apply(inst, DNAHybridizerRecipe::new));
|
||||
).apply(inst, (inputs, output) -> new DNAHybridizerRecipe(Constants.rl("dna_hybridizer"), inputs, output)));
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, DNAHybridizerRecipe> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, r) -> {
|
||||
@@ -106,7 +106,8 @@ public record DNAHybridizerRecipe(ResourceLocation id, NonNullList<Ingredient> i
|
||||
int size = buf.readVarInt();
|
||||
NonNullList<Ingredient> ins = NonNullList.create();
|
||||
for(int i=0; i<size; i++) ins.add(Ingredient.CONTENTS_STREAM_CODEC.decode(buf));
|
||||
return new DNAHybridizerRecipe(ins, ItemStack.STREAM_CODEC.decode(buf));
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
return new DNAHybridizerRecipe(Constants.rl("dna_hybridizer"), ins, output);
|
||||
}
|
||||
);
|
||||
@Override public MapCodec<DNAHybridizerRecipe> codec() { return CODEC; }
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ public record EmbryoCalcificationMachineRecipe(ResourceLocation id, NonNullList<
|
||||
list -> DataResult.success(List.copyOf(list))
|
||||
).forGetter(EmbryoCalcificationMachineRecipe::inputs),
|
||||
ItemStack.CODEC.fieldOf("result").forGetter(EmbryoCalcificationMachineRecipe::output)
|
||||
).apply(instance, EmbryoCalcificationMachineRecipe::new));
|
||||
).apply(instance, (inputs, output) -> new EmbryoCalcificationMachineRecipe(Constants.rl("embryo_calcification_machine"), inputs, output)));
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, EmbryoCalcificationMachineRecipe> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, recipe) -> {
|
||||
@@ -80,7 +80,7 @@ public record EmbryoCalcificationMachineRecipe(ResourceLocation id, NonNullList<
|
||||
int size = buf.readVarInt();
|
||||
NonNullList<Ingredient> ins = NonNullList.create();
|
||||
for(int i=0; i<size; i++) ins.add(Ingredient.CONTENTS_STREAM_CODEC.decode(buf));
|
||||
return new EmbryoCalcificationMachineRecipe(ins, ItemStack.STREAM_CODEC.decode(buf));
|
||||
return new EmbryoCalcificationMachineRecipe(Constants.rl("embryo_calcification_machine"), ins, ItemStack.STREAM_CODEC.decode(buf));
|
||||
}
|
||||
);
|
||||
@Override public MapCodec<EmbryoCalcificationMachineRecipe> codec() { return CODEC; }
|
||||
|
||||
@@ -150,7 +150,11 @@ public class EmbryonicMachineRecipe implements Recipe<EmbryonicMachineRecipeInpu
|
||||
buf -> {
|
||||
NonNullList<Ingredient> inputs = ByteBufCodecs.collection(NonNullList::createWithCapacity, Ingredient.CONTENTS_STREAM_CODEC).decode(buf);
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
Map<ResourceLocation, Integer> weights = buf.readMap(ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT);
|
||||
Map<ResourceLocation, Integer> weights = buf.readMap(
|
||||
HashMap<ResourceLocation, Integer>::new,
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
ByteBufCodecs.VAR_INT
|
||||
);
|
||||
return new EmbryonicMachineRecipe(inputs, output, weights);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -171,23 +171,27 @@ public class FossilCleanerRecipe implements Recipe<FossilCleanerRecipeInput> {
|
||||
WEIGHTS_CODEC.optionalFieldOf("fossil_weights", Map.of()).forGetter(FossilCleanerRecipe::weights)
|
||||
).apply(inst, FossilCleanerRecipe::new));
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, FossilCleanerRecipe> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, recipe) -> {
|
||||
ByteBufCodecs.collection(NonNullList::createWithCapacity, Ingredient.CONTENTS_STREAM_CODEC).encode(buf, recipe.inputs());
|
||||
ItemStack.STREAM_CODEC.encode(buf, recipe.output());
|
||||
buf.writeMap(recipe.weights(), ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT);
|
||||
},
|
||||
buf -> {
|
||||
NonNullList<Ingredient> inputs = ByteBufCodecs.collection(NonNullList::createWithCapacity, Ingredient.CONTENTS_STREAM_CODEC).decode(buf);
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
Map<ResourceLocation, Integer> weights = buf.readMap(ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT);
|
||||
return new FossilCleanerRecipe(inputs, output, weights);
|
||||
}
|
||||
);
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, FossilCleanerRecipe> STREAM_CODEC = StreamCodec.of(
|
||||
(buf, recipe) -> {
|
||||
ByteBufCodecs.collection(NonNullList::createWithCapacity, Ingredient.CONTENTS_STREAM_CODEC).encode(buf, recipe.inputs());
|
||||
ItemStack.STREAM_CODEC.encode(buf, recipe.output());
|
||||
buf.writeMap(recipe.weights(), ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT);
|
||||
},
|
||||
buf -> {
|
||||
NonNullList<Ingredient> inputs = ByteBufCodecs.collection(NonNullList::createWithCapacity, Ingredient.CONTENTS_STREAM_CODEC).decode(buf);
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
Map<ResourceLocation, Integer> weights = buf.readMap(
|
||||
HashMap<ResourceLocation, Integer>::new,
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
ByteBufCodecs.VAR_INT
|
||||
);
|
||||
return new FossilCleanerRecipe(inputs, output, weights);
|
||||
}
|
||||
);
|
||||
|
||||
@Override public MapCodec<FossilCleanerRecipe> codec() { return CODEC; }
|
||||
@Override public StreamCodec<RegistryFriendlyByteBuf, FossilCleanerRecipe> streamCodec() { return STREAM_CODEC; }
|
||||
*///?} else {
|
||||
@Override public MapCodec<FossilCleanerRecipe> codec() { return CODEC; }
|
||||
@Override public StreamCodec<RegistryFriendlyByteBuf, FossilCleanerRecipe> streamCodec() { return STREAM_CODEC; }
|
||||
*///?} else {
|
||||
@Override
|
||||
public FossilCleanerRecipe fromJson(ResourceLocation id, JsonObject json) {
|
||||
ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "result"));
|
||||
|
||||
@@ -174,7 +174,11 @@ public class FossilGrinderRecipe implements Recipe<FossilGrinderRecipeInput> {
|
||||
buf -> {
|
||||
NonNullList<Ingredient> inputs = ByteBufCodecs.collection(NonNullList::createWithCapacity, Ingredient.CONTENTS_STREAM_CODEC).decode(buf);
|
||||
ItemStack output = ItemStack.STREAM_CODEC.decode(buf);
|
||||
Map<ResourceLocation, Integer> weights = buf.readMap(ResourceLocation.STREAM_CODEC, ByteBufCodecs.VAR_INT);
|
||||
Map<ResourceLocation, Integer> weights = buf.readMap(
|
||||
HashMap<ResourceLocation, Integer>::new,
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
ByteBufCodecs.VAR_INT
|
||||
);
|
||||
return new FossilGrinderRecipe(inputs, output, weights);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -67,15 +67,7 @@ public class GeneratorScreen extends AbstractContainerScreen<GeneratorMenu> {
|
||||
|
||||
renderFuelBurning(guiGraphics, x, y);
|
||||
}
|
||||
//? if >1.20.1 {
|
||||
/*private void renderFuelBurning(GuiGraphics guiGraphics, int x, int y) {
|
||||
if(this.menu.isBurning()) {
|
||||
int l = Mth.ceil(this.menu.getFuelProgress() * 13.0F) + 1;
|
||||
guiGraphics.blitSprite(LIT_PROGRESS_TEXTURE, 14, 14, 0, 14 - l,
|
||||
x + 80, y + 18 + 14 - l, 14, l);
|
||||
}
|
||||
}
|
||||
*///?} else {
|
||||
|
||||
private void renderFuelBurning(GuiGraphics guiGraphics, int x, int y) {
|
||||
if (this.menu.isBurning()) {
|
||||
float progress = Mth.clamp(this.menu.getFuelProgress(), 0.0F, 1.0F);
|
||||
@@ -95,7 +87,6 @@ public class GeneratorScreen extends AbstractContainerScreen<GeneratorMenu> {
|
||||
guiGraphics.blit(LIT_PROGRESS_TEXTURE, destX, destY, srcU, srcV, width, height, texW, texH);
|
||||
}
|
||||
}
|
||||
//?}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
||||
|
||||
@@ -75,9 +75,23 @@ public class TankScreen extends AbstractContainerScreen<TankMenu> {
|
||||
renderBackground(guiGraphics);
|
||||
//?}
|
||||
super.render(guiGraphics, mouseX, mouseY, delta);
|
||||
|
||||
int x = (width - imageWidth) / 2;
|
||||
int y = (height - imageHeight) / 2;
|
||||
if (MouseUtil.isMouseOver(mouseX, mouseY, x + 80, y + 8, fluidRenderer.getWidth(), fluidRenderer.getHeight())) {
|
||||
renderHoverHighlight(guiGraphics, x + 80, y + 8, fluidRenderer.getWidth(), fluidRenderer.getHeight());
|
||||
}
|
||||
|
||||
renderTooltip(guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private static void renderHoverHighlight(GuiGraphics guiGraphics, int x, int y, int width, int height) {
|
||||
guiGraphics.pose().pushPose();
|
||||
guiGraphics.pose().translate(0, 0, 200);
|
||||
guiGraphics.fillGradient(x, y, x + width, y + height, 0x80FFFFFF, 0x80FFFFFF);
|
||||
guiGraphics.pose().popPose();
|
||||
}
|
||||
|
||||
public static boolean isMouseAboveArea(int pMouseX, int pMouseY, int x, int y, int offsetX, int offsetY, FluidTankRenderer renderer) {
|
||||
return MouseUtil.isMouseOver(pMouseX, pMouseY, x + offsetX, y + offsetY, renderer.getWidth(), renderer.getHeight());
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 831 B |
@@ -12,6 +12,10 @@ public class JRModClient implements ClientModInitializer {
|
||||
public void onInitializeClient() {
|
||||
CommonClientClass.init();
|
||||
|
||||
//? if <=1.20.1 {
|
||||
CommonClientClass.registerScreens();
|
||||
//?}
|
||||
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.TANK.get(), RenderType.translucent());
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.INCUBATOR.get(), RenderType.translucent());
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.DNA_EXTRACTOR.get(), RenderType.translucent());
|
||||
|
||||
@@ -188,26 +188,24 @@ public class FabricRecipeProvider extends net.fabricmc.fabric.api.datagen.v1.pro
|
||||
//?}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dnaHybridizing(ItemLike result, int count, ItemLike catalyst, ItemLike... ingredients) {
|
||||
//? if >1.20.1 {
|
||||
/*DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count)
|
||||
.setCatalyst(catalyst);
|
||||
@Override
|
||||
public void dnaHybridizing(ItemLike result, int count, ItemLike... ingredients) {
|
||||
//? if >1.20.1 {
|
||||
/*DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_dna", has(ingredients[0]))
|
||||
.save(output);
|
||||
*///?} else {
|
||||
DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_catalyst", has(catalyst))
|
||||
.save(output);
|
||||
*///?} else {
|
||||
DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count)
|
||||
.setCatalyst(catalyst);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_catalyst", has(catalyst))
|
||||
builder.unlockedBy("has_dna", has(ingredients[0]))
|
||||
.save(output);
|
||||
//?}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void embryonicMachine(ItemLike syringe, ItemLike dna, ItemLike catalyst, ItemLike result, int count) {
|
||||
|
||||
+59
-30
@@ -3,6 +3,7 @@ package net.cmr.jurassicrevived.platform;
|
||||
import dev.architectury.fluid.FluidStack;
|
||||
import net.cmr.jurassicrevived.platform.services.IItemFluidHelper;
|
||||
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.ItemVariant;
|
||||
@@ -16,20 +17,32 @@ import net.minecraft.world.level.material.Fluids;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricItemFluidHelper implements IItemFluidHelper {
|
||||
private static final long MB_PER_BUCKET = 1000L;
|
||||
|
||||
private static long dropletsToMb(long droplets) {
|
||||
if (droplets <= 0) return 0;
|
||||
return Math.max(1, droplets * MB_PER_BUCKET / FluidConstants.BUCKET);
|
||||
}
|
||||
|
||||
private static long mbToDroplets(long mb) {
|
||||
if (mb <= 0) return 0;
|
||||
return mb * FluidConstants.BUCKET / MB_PER_BUCKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FluidStack> getContainedFluid(ItemStack stack) {
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(stack.copy());
|
||||
if (stack.is(Items.WATER_BUCKET)) return Optional.of(FluidStack.create(Fluids.WATER, 1000));
|
||||
if (stack.is(Items.LAVA_BUCKET)) return Optional.of(FluidStack.create(Fluids.LAVA, 1000));
|
||||
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(ItemVariant.of(stack), stack.getCount());
|
||||
Storage<FluidVariant> storage = ctx.find(FluidStorage.ITEM);
|
||||
if (storage == null) {
|
||||
if (stack.is(Items.WATER_BUCKET)) return Optional.of(FluidStack.create(Fluids.WATER, 1000));
|
||||
if (stack.is(Items.LAVA_BUCKET)) return Optional.of(FluidStack.create(Fluids.LAVA, 1000));
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
for (StorageView<FluidVariant> view : storage) {
|
||||
if (!view.isResourceBlank() && view.getAmount() > 0) {
|
||||
return Optional.of(FluidStack.create(view.getResource().getFluid(), view.getAmount()));
|
||||
return Optional.of(FluidStack.create(view.getResource().getFluid(), dropletsToMb(view.getAmount())));
|
||||
}
|
||||
}
|
||||
return Optional.of(FluidStack.empty());
|
||||
@@ -37,31 +50,37 @@ public class FabricItemFluidHelper implements IItemFluidHelper {
|
||||
|
||||
@Override
|
||||
public TransferResult drain(ItemStack stack, long amount, boolean simulate) {
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(stack.copy());
|
||||
if (stack.is(Items.WATER_BUCKET) && amount >= 1000) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.BUCKET));
|
||||
}
|
||||
if (stack.is(Items.LAVA_BUCKET) && amount >= 1000) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.BUCKET));
|
||||
}
|
||||
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(ItemVariant.of(stack), stack.getCount());
|
||||
Storage<FluidVariant> storage = ctx.find(FluidStorage.ITEM);
|
||||
if (storage == null) {
|
||||
if (stack.is(Items.WATER_BUCKET) && amount >= 1000) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.BUCKET));
|
||||
}
|
||||
if (stack.is(Items.LAVA_BUCKET) && amount >= 1000) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.BUCKET));
|
||||
}
|
||||
return new TransferResult(0, stack);
|
||||
}
|
||||
|
||||
try (Transaction tx = Transaction.openOuter()) {
|
||||
long extracted = 0;
|
||||
long requestedDroplets = mbToDroplets(amount);
|
||||
long extractedDroplets = 0;
|
||||
|
||||
for (StorageView<FluidVariant> view : storage) {
|
||||
if (!view.isResourceBlank()) {
|
||||
extracted = storage.extract(view.getResource(), amount, tx);
|
||||
if (extracted > 0) break;
|
||||
extractedDroplets = storage.extract(view.getResource(), requestedDroplets, tx);
|
||||
if (extractedDroplets > 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (extracted > 0) {
|
||||
if (extractedDroplets > 0) {
|
||||
long extractedMb = dropletsToMb(extractedDroplets);
|
||||
|
||||
if (!simulate) tx.commit();
|
||||
|
||||
ItemStack resultStack = ctx.getItemVariant().toStack((int) ctx.getAmount());
|
||||
return new TransferResult(extracted, resultStack);
|
||||
return new TransferResult(extractedMb, resultStack);
|
||||
}
|
||||
}
|
||||
return new TransferResult(0, stack);
|
||||
@@ -69,26 +88,32 @@ public class FabricItemFluidHelper implements IItemFluidHelper {
|
||||
|
||||
@Override
|
||||
public TransferResult fill(ItemStack stack, FluidStack fluid, long amount, boolean simulate) {
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(stack.copy());
|
||||
if (stack.is(Items.BUCKET) && amount >= 1000) {
|
||||
if (fluid.getFluid().isSame(Fluids.WATER)) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.WATER_BUCKET));
|
||||
}
|
||||
if (fluid.getFluid().isSame(Fluids.LAVA)) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.LAVA_BUCKET));
|
||||
}
|
||||
}
|
||||
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(ItemVariant.of(stack), stack.getCount());
|
||||
Storage<FluidVariant> storage = ctx.find(FluidStorage.ITEM);
|
||||
if (storage == null) {
|
||||
if (stack.is(Items.BUCKET) && amount >= 1000) {
|
||||
if (fluid.getFluid().isSame(Fluids.WATER)) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.WATER_BUCKET));
|
||||
}
|
||||
if (fluid.getFluid().isSame(Fluids.LAVA)) {
|
||||
return new TransferResult(1000, simulate ? stack : new ItemStack(Items.LAVA_BUCKET));
|
||||
}
|
||||
}
|
||||
return new TransferResult(0, stack);
|
||||
}
|
||||
|
||||
try (Transaction tx = Transaction.openOuter()) {
|
||||
long inserted = storage.insert(FluidVariant.of(fluid.getFluid()), amount, tx);
|
||||
if (inserted > 0) {
|
||||
long requestedDroplets = mbToDroplets(amount);
|
||||
long insertedDroplets = storage.insert(FluidVariant.of(fluid.getFluid()), requestedDroplets, tx);
|
||||
|
||||
if (insertedDroplets > 0) {
|
||||
long insertedMb = dropletsToMb(insertedDroplets);
|
||||
|
||||
if (!simulate) tx.commit();
|
||||
|
||||
ItemStack resultStack = ctx.getItemVariant().toStack((int) ctx.getAmount());
|
||||
return new TransferResult(inserted, resultStack);
|
||||
return new TransferResult(insertedMb, resultStack);
|
||||
}
|
||||
}
|
||||
return new TransferResult(0, stack);
|
||||
@@ -96,8 +121,12 @@ public class FabricItemFluidHelper implements IItemFluidHelper {
|
||||
|
||||
@Override
|
||||
public boolean isFluidHandler(ItemStack stack) {
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(stack);
|
||||
if (stack.is(Items.BUCKET) || stack.is(Items.WATER_BUCKET) || stack.is(Items.LAVA_BUCKET)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ContainerItemContext ctx = ContainerItemContext.withConstant(ItemVariant.of(stack), stack.getCount());
|
||||
Storage<FluidVariant> storage = ctx.find(FluidStorage.ITEM);
|
||||
return storage != null || stack.is(Items.BUCKET) || stack.is(Items.WATER_BUCKET) || stack.is(Items.LAVA_BUCKET);
|
||||
return storage != null;
|
||||
}
|
||||
}
|
||||
|
||||
+105
-25
@@ -12,18 +12,16 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import dev.architectury.fluid.FluidStack;
|
||||
import net.cmr.jurassicrevived.platform.transfer.InternalFluidHandler;
|
||||
import net.cmr.jurassicrevived.platform.transfer.InternalFluidProvider;
|
||||
import team.reborn.energy.api.EnergyStorage;
|
||||
import net.cmr.jurassicrevived.platform.transfer.PlatformEnergyHandler;
|
||||
import net.cmr.jurassicrevived.platform.transfer.PlatformFluidHandler;
|
||||
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.storage.StorageView;
|
||||
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
|
||||
//import net.fabricmc.fabric.api.transfer.v1.energy.EnergyStorage;
|
||||
//import team.reborn.energy.api.EnergyStorage;
|
||||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -31,6 +29,17 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricTransferHelper implements ITransferHelper {
|
||||
private static final long MB_PER_BUCKET = 1000L;
|
||||
|
||||
private static long dropletsToMb(long droplets) {
|
||||
if (droplets <= 0) return 0;
|
||||
return Math.max(1, droplets * MB_PER_BUCKET / FluidConstants.BUCKET);
|
||||
}
|
||||
|
||||
private static long mbToDroplets(long mb) {
|
||||
if (mb <= 0) return 0;
|
||||
return mb * FluidConstants.BUCKET / MB_PER_BUCKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlatformItemHandler> getItemHandler(Level level, BlockPos pos, Direction side) {
|
||||
@@ -41,6 +50,13 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
|
||||
@Override
|
||||
public Optional<PlatformFluidHandler> getFluidHandler(Level level, BlockPos pos, Direction side) {
|
||||
if (level.getBlockEntity(pos) instanceof InternalFluidProvider provider) {
|
||||
InternalFluidHandler handler = provider.getFluidHandler(side);
|
||||
if (handler != null) {
|
||||
return Optional.of(new DirectInternalFluidHandler(handler));
|
||||
}
|
||||
}
|
||||
|
||||
var storage = FluidStorage.SIDED.find(level, pos, side);
|
||||
if (storage == null) return Optional.empty();
|
||||
return Optional.of(new FabricFluidHandler(storage));
|
||||
@@ -49,7 +65,8 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
@Override
|
||||
public Optional<PlatformEnergyHandler> getEnergyHandler(Level level, BlockPos pos, Direction side) {
|
||||
EnergyStorage storage = EnergyStorage.SIDED.find(level, pos, side);
|
||||
return Optional.empty();
|
||||
if (storage == null) return Optional.empty();
|
||||
return Optional.of(new FabricEnergyHandler(storage));
|
||||
}
|
||||
|
||||
public static class InternalFluidStorage implements Storage<FluidVariant> {
|
||||
@@ -65,18 +82,19 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FluidStack stack = FluidStack.create(resource.getFluid(), maxAmount);
|
||||
long inserted = handler.fill(stack, true);
|
||||
long maxAmountMb = dropletsToMb(maxAmount);
|
||||
FluidStack stack = FluidStack.create(resource.getFluid(), maxAmountMb);
|
||||
long insertedMb = handler.fill(stack, true);
|
||||
|
||||
if (inserted > 0) {
|
||||
if (insertedMb > 0) {
|
||||
transaction.addCloseCallback((tx, result) -> {
|
||||
if (result.wasCommitted()) {
|
||||
handler.fill(FluidStack.create(resource.getFluid(), inserted), false);
|
||||
handler.fill(FluidStack.create(resource.getFluid(), insertedMb), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return inserted;
|
||||
return Math.min(maxAmount, mbToDroplets(insertedMb));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,17 +108,18 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long extracted = Math.min(maxAmount, stored.getAmount());
|
||||
long maxAmountMb = dropletsToMb(maxAmount);
|
||||
long extractedMb = Math.min(maxAmountMb, stored.getAmount());
|
||||
|
||||
if (extracted > 0) {
|
||||
if (extractedMb > 0) {
|
||||
transaction.addCloseCallback((tx, result) -> {
|
||||
if (result.wasCommitted()) {
|
||||
handler.drain(extracted, false);
|
||||
handler.drain(extractedMb, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return extracted;
|
||||
return Math.min(maxAmount, mbToDroplets(extractedMb));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,12 +133,12 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
|
||||
@Override
|
||||
public long getAmount() {
|
||||
return stored.getAmount();
|
||||
return mbToDroplets(stored.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return handler.getCapacity();
|
||||
return mbToDroplets(handler.getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,6 +154,44 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DirectInternalFluidHandler implements PlatformFluidHandler {
|
||||
private final InternalFluidHandler handler;
|
||||
|
||||
private DirectInternalFluidHandler(InternalFluidHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<FluidStack> getExtractableFluids() {
|
||||
FluidStack stored = handler.getFluid();
|
||||
if (stored.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return List.of(stored.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long extract(FluidStack stack, long amount, boolean simulate) {
|
||||
FluidStack stored = handler.getFluid();
|
||||
if (stored.isEmpty() || stored.getFluid() != stack.getFluid()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return handler.drain(amount, simulate).getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long insert(FluidStack stack, long amount, boolean simulate) {
|
||||
if (stack.isEmpty() || amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FluidStack toInsert = stack.copy();
|
||||
toInsert.setAmount(amount);
|
||||
return handler.fill(toInsert, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FabricFluidHandler implements PlatformFluidHandler {
|
||||
private final Storage<FluidVariant> storage;
|
||||
|
||||
@@ -148,7 +205,7 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
for (StorageView<FluidVariant> view : storage) {
|
||||
if (view.isResourceBlank()) continue;
|
||||
FluidVariant v = view.getResource();
|
||||
long amt = view.getAmount();
|
||||
long amt = dropletsToMb(view.getAmount());
|
||||
if (amt > 0) {
|
||||
FluidStack stack = FluidStack.create(v.getFluid(), amt);
|
||||
stacks.add(stack);
|
||||
@@ -160,34 +217,57 @@ public class FabricTransferHelper implements ITransferHelper {
|
||||
@Override
|
||||
public long extract(FluidStack stack, long amount, boolean simulate) {
|
||||
try (Transaction tx = Transaction.openOuter()) {
|
||||
long extracted = storage.extract(FluidVariant.of(stack.getFluid()), amount, tx);
|
||||
long extractedDroplets = storage.extract(FluidVariant.of(stack.getFluid()), mbToDroplets(amount), tx);
|
||||
if (!simulate) tx.commit();
|
||||
return extracted;
|
||||
return dropletsToMb(extractedDroplets);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long insert(FluidStack stack, long amount, boolean simulate) {
|
||||
try (Transaction tx = Transaction.openOuter()) {
|
||||
long inserted = storage.insert(FluidVariant.of(stack.getFluid()), amount, tx);
|
||||
long insertedDroplets = storage.insert(FluidVariant.of(stack.getFluid()), mbToDroplets(amount), tx);
|
||||
if (!simulate) tx.commit();
|
||||
return inserted;
|
||||
return dropletsToMb(insertedDroplets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class FabricEnergyHandler implements PlatformEnergyHandler {
|
||||
private FabricEnergyHandler() {
|
||||
private final EnergyStorage storage;
|
||||
|
||||
private FabricEnergyHandler(EnergyStorage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extract(int amount, boolean simulate) {
|
||||
return 0;
|
||||
if (amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try (Transaction tx = Transaction.openOuter()) {
|
||||
long extracted = storage.extract(amount, tx);
|
||||
if (!simulate) {
|
||||
tx.commit();
|
||||
}
|
||||
return (int) Math.min(Integer.MAX_VALUE, extracted);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(int amount, boolean simulate) {
|
||||
return 0;
|
||||
if (amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try (Transaction tx = Transaction.openOuter()) {
|
||||
long inserted = storage.insert(amount, tx);
|
||||
if (!simulate) {
|
||||
tx.commit();
|
||||
}
|
||||
return (int) Math.min(Integer.MAX_VALUE, inserted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraftforge.client.ConfigScreenHandler;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod(Constants.MOD_ID)
|
||||
@@ -21,11 +22,13 @@ public class JRMod {
|
||||
|
||||
EventBuses.registerModEventBus(Constants.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
|
||||
|
||||
// Use Forge to bootstrap the Common mod.
|
||||
// Use Forge to bootstrap the Common mod.
|
||||
CommonClass.init();
|
||||
|
||||
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> CommonClientClass::init);
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
|
||||
|
||||
ModLoadingContext.get().registerExtensionPoint(
|
||||
ConfigScreenHandler.ConfigScreenFactory.class,
|
||||
() -> new ConfigScreenHandler.ConfigScreenFactory(
|
||||
@@ -34,4 +37,8 @@ public class JRMod {
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void clientSetup(FMLClientSetupEvent event) {
|
||||
event.enqueueWork(CommonClientClass::registerScreens);
|
||||
}
|
||||
}
|
||||
+9
-10
@@ -112,16 +112,15 @@ public class ForgeRecipeProvider extends RecipeProvider implements ModRecipeProv
|
||||
.save(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dnaHybridizing(ItemLike result, int count, ItemLike catalyst, ItemLike... ingredients) {
|
||||
DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count)
|
||||
.setCatalyst(catalyst);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_catalyst", has(catalyst))
|
||||
.save(output);
|
||||
}
|
||||
@Override
|
||||
public void dnaHybridizing(ItemLike result, int count, ItemLike... ingredients) {
|
||||
DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_dna", has(ingredients[0]))
|
||||
.save(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void embryonicMachine(ItemLike syringe, ItemLike dna, ItemLike catalyst, ItemLike result, int count) {
|
||||
|
||||
+11
-12
@@ -115,18 +115,17 @@ public class NeoForgeRecipeProvider extends RecipeProvider implements ModRecipeP
|
||||
//?}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dnaHybridizing(ItemLike result, int count, ItemLike catalyst, ItemLike... ingredients) {
|
||||
//? if >1.20.1 {
|
||||
DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count)
|
||||
.setCatalyst(catalyst);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_catalyst", has(catalyst))
|
||||
.save(output);
|
||||
//?}
|
||||
}
|
||||
@Override
|
||||
public void dnaHybridizing(ItemLike result, int count, ItemLike... ingredients) {
|
||||
//? if >1.20.1 {
|
||||
DNAHybridizingRecipeBuilder builder = new DNAHybridizingRecipeBuilder(result, count);
|
||||
for (ItemLike ingredient : ingredients) {
|
||||
builder.addIngredient(ingredient);
|
||||
}
|
||||
builder.unlockedBy("has_dna", has(ingredients[0]))
|
||||
.save(output);
|
||||
//?}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void embryonicMachine(ItemLike syringe, ItemLike dna, ItemLike catalyst, ItemLike result, int count) {
|
||||
|
||||
@@ -2,11 +2,8 @@ package net.cmr.jurassicrevived.event;
|
||||
|
||||
import net.cmr.jurassicrevived.Constants;
|
||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||
import net.cmr.jurassicrevived.block.entity.custom.FossilCleanerBlockEntity;
|
||||
import net.cmr.jurassicrevived.block.entity.custom.GeneratorBlockEntity;
|
||||
import net.cmr.jurassicrevived.block.entity.custom.*;
|
||||
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||
import net.cmr.jurassicrevived.block.entity.custom.PowerCellBlockEntity;
|
||||
import net.cmr.jurassicrevived.block.entity.custom.TankBlockEntity;
|
||||
import net.cmr.jurassicrevived.neoforge.capabilities.NeoForgeEnergyStorage;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
@@ -40,12 +37,33 @@ public class NeoForgeEvents
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.GENERATOR_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((GeneratorBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.DNA_ANALYZER_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((DNAAnalyzerBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.DNA_EXTRACTOR_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((DNAExtractorBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.DNA_HYBRIDIZER_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((DNAHybridizerBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.EMBRYO_CALCIFICATION_MACHINE_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((EmbryoCalcificationMachineBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.EMBRYONIC_MACHINE_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((EmbryonicMachineBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.FOSSIL_CLEANER_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((FossilCleanerBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.FOSSIL_GRINDER_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((FossilGrinderBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.INCUBATOR_BE.get(),
|
||||
(be, side) -> new NeoForgeEnergyStorage(((IncubatorBlockEntity) be).getEnergyStorage(side)));
|
||||
|
||||
// Fluids
|
||||
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, ModBlockEntities.TANK_BE.get(),
|
||||
(be, side) -> new TankFluidAdapter(((TankBlockEntity) be).getTank(side)));
|
||||
|
||||
//event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, ModBlockEntities.FOSSIL_CLEANER_BE.get(),
|
||||
// (be, side) -> new TankFluidAdapter(((FossilCleanerBlockEntity) be).getTank(side)));
|
||||
}
|
||||
|
||||
private record TankFluidAdapter(TankBlockEntity.TankFluidHandler tank) implements IFluidHandler {
|
||||
|
||||
Reference in New Issue
Block a user