Skip to content

Commit

Permalink
Merge branch 'main' into LCT_recipe_visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
IneMEGAmaxi committed Nov 23, 2022
2 parents ef7b2ab + 3ca086f commit 39f5306
Show file tree
Hide file tree
Showing 131 changed files with 1,911 additions and 161 deletions.
56 changes: 55 additions & 1 deletion src/main/java/be/uantwerpen/minelabs/MinelabsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import be.uantwerpen.minelabs.block.entity.BlockEntities;
import be.uantwerpen.minelabs.entity.Entities;
import be.uantwerpen.minelabs.event.ClientModsEvents;
import be.uantwerpen.minelabs.fluid.Fluids;
import be.uantwerpen.minelabs.gui.ScreenHandlers;
import be.uantwerpen.minelabs.gui.ionic_gui.IonicScreen;
import be.uantwerpen.minelabs.gui.lab_chest_gui.LabChestScreen;
Expand All @@ -21,6 +22,8 @@
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
Expand All @@ -29,6 +32,7 @@
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.resource.Resource;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -136,10 +140,45 @@ public void onInitializeClient() {
registerErlenmeyer(Items.ERLENMEYER_He, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_Ne, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_Ar, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_CL2O,0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_H2CO3,0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_CH4S,0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_CH2O,0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_BH3,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_HF,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_SIH4,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_PH3,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_H2S,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_CF4,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_BF3,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_BCL3,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_SO2,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_CLF,0xFFFFFF, 0);
registerErlenmeyer(Items.ERLENMEYER_F2,0xFFFFFF, 0);

//Fluids
registerErlenmeyer(Items.ERLENMEYER_HNO3, 0xFFCC33, 0);
registerErlenmeyer(Items.ERLENMEYER_H2O, 0x3495eb, 0);
// public static Block ACID = Registry.register(Registry.BLOCK, new Identifier(Minelabs.MOD_ID, "acid"), new FluidBlock(be.uantwerpen.minelabs.item.Items.STILL_ACID, FabricBlockSettings.copy(net.minecraft.block.)){});
registerErlenmeyer(Items.ERLENMEYER_NCL3, 0xe8dc5a, 0);
registerErlenmeyer(Items.ERLENMEYER_CS2, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_CCL4, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_PCl3, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_SCl2, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_HCN, 0xCCCCFF, 0);
registerErlenmeyer(Items.ERLENMEYER_CH4O, 0xAFAFAF, 0);
registerErlenmeyer(Items.ERLENMEYER_SICL4, 0xAFAFAF, 0);

registerErlenmeyerFluid(Fluids.STILL_HNO3, Fluids.FLOWING_HNO3, 0xA1FFCC33);
registerErlenmeyerFluid(Fluids.STILL_H2O, Fluids.FLOWING_H2O, 0xA10084FF);
registerErlenmeyerFluid(Fluids.STILL_NCl3, Fluids.FLOWING_NCl3, 0xA1E8DC5A);
registerErlenmeyerFluid(Fluids.STILL_HCN, Fluids.FLOWING_HCN, 0xA1CCCCFF);
registerErlenmeyerFluid(Fluids.STILL_NCl3, Fluids.FLOWING_NCl3, 0xA1e8dc5a); // Default
registerErlenmeyerFluid(Fluids.STILL_CS2, Fluids.FLOWING_CS2, 0xA1AFAFAF);
registerErlenmeyerFluid(Fluids.STILL_CCl4, Fluids.FLOWING_CCl4, 0xA1AFAFAF);
registerErlenmeyerFluid(Fluids.STILL_PCl3, Fluids.FLOWING_PCl3, 0xA1AFAFAF);
registerErlenmeyerFluid(Fluids.STILL_SCl2, Fluids.FLOWING_SCl2, 0xA1AFAFAF);
registerErlenmeyerFluid(Fluids.STILL_CH4O, Fluids.FLOWING_CH4O, 0xA1AFAFAF);
registerErlenmeyerFluid(Fluids.STILL_SiCl4, Fluids.FLOWING_SiCl4, 0xA1AFAFAF);

//Lewis Data Sync
ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.LEWISDATASYNC, (c, h, b, s) -> LewisDataPacket.receive(c.world, b, s));
Expand All @@ -155,5 +194,20 @@ public void registerErlenmeyer(Item item, int color, int index) {
}, item);
}

/**
* Fully register the Fluid rendering, water texture recolored and transparent
*
* @param still : Still Fluid
* @param flowing : Flowing Fluid
* @param tint : Tint in ARGB (alpha / R / G /B) use as hex: 0x........
*/
public void registerErlenmeyerFluid(Fluid still, Fluid flowing, int tint) {
FluidRenderHandlerRegistry.INSTANCE.register(still, flowing, new SimpleFluidRenderHandler(
new Identifier("minecraft:block/water_still"),
new Identifier("minecraft:block/water_flow"),
tint));
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), still, flowing);
}

}

11 changes: 10 additions & 1 deletion src/main/java/be/uantwerpen/minelabs/block/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ public class Blocks {
.mapColor(MapColor.WHITE).strength(2f).nonOpaque().luminance(state -> state.get(MologramBlock.LIT) ? 8 : 0)), "mologram");
public static final Block LEWIS_BLOCK = register(new LewisBlock(FabricBlockSettings.of(Material.METAL).nonOpaque()), "lewis_block");
public static final Block IONIC_BLOCK = register(new IonicBlock(FabricBlockSettings.of(Material.METAL).nonOpaque()), "ionic_block");
public static final Block ACID = register(new FluidBlock(Fluids.STILL_ACID, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "acid");
public static final Block HNO3 = register(new FluidBlock(Fluids.STILL_HNO3, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "hno3");
public static final Block H2O = register(new FluidBlock(Fluids.STILL_H2O, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "h2o");
public static final Block CS2 = register(new FluidBlock(Fluids.STILL_CS2, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "cs2");
public static final Block CCl4 = register(new FluidBlock(Fluids.STILL_CCl4, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "ccl4");
public static final Block PCl3 = register(new FluidBlock(Fluids.STILL_PCl3, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "pcl3");
public static final Block SCl2 = register(new FluidBlock(Fluids.STILL_SCl2, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "scl2");
public static final Block NCl3 = register(new FluidBlock(Fluids.STILL_NCl3, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "ncl3");
public static final Block HCN = register(new FluidBlock(Fluids.STILL_HCN, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "hcn");
public static final Block CH4O = register(new FluidBlock(Fluids.STILL_CH4O, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "ch4o");
public static final Block SICL4 = register(new FluidBlock(Fluids.STILL_SiCl4, FabricBlockSettings.copy(net.minecraft.block.Blocks.WATER)), "sicl4");
public static final Block BOHR_BLOCK = register(new BohrBlock(), "bohr_block");

public static final Block ERLENMEYER_STAND = register(new ErlenmeyerBlock(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package be.uantwerpen.minelabs.block.entity;

import be.uantwerpen.minelabs.inventory.ImplementedInventory;
import be.uantwerpen.minelabs.item.MoleculeItem;
import be.uantwerpen.minelabs.item.IMoleculeItem;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.inventory.Inventories;
Expand Down Expand Up @@ -86,7 +86,7 @@ public DefaultedList<ItemStack> getItems() {
@Override
public boolean canInsert(int slot, ItemStack stack, @Nullable Direction side) {
if (this.isEmpty()) {
if (!(stack.getItem() instanceof MoleculeItem)) {
if (!(stack.getItem() instanceof IMoleculeItem)) {
return false;
}
if (side == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum Atom {
SODIUM(11, "Na", 0.9, AtomType.ALKALI_METAL, 1, 12, Items.SODIUM_ATOM, 0x5700A3),// violet
MAGNESIUM(12, "Mg", 1.2, AtomType.ALKALINE_EARTH_METAL, 2, 12, Items.MAGNESIUM_ATOM, 0x113900),//dark green
ALUMINIUM(13, "Al", 1.5, AtomType.POST_TRANSITION_METAL, 3, 14, Items.ALUMINIUM_ATOM, 0x4A4A50),//grey
SILICON(14, "Si", 1.8, AtomType.NON_METAL, 4, 14, Items.SILICON_ATOM, 0x00079D),//blue
SILICON(14, "Si", 1.8, AtomType.NON_METAL, 4, 14, Items.SILICON_ATOM, 0x7B6B46),//blue
PHOSPHORUS(15, "P", 2.1, AtomType.NON_METAL, 5, 16, Items.PHOSPHORUS_ATOM, 0x8E5A0D),//orange
SULFUR(16, "S", 2.5, AtomType.NON_METAL, 6, 16, Items.SULFUR_ATOM, 0xADA10F), //yellow
CHLORINE(17, "Cl", 3.0, AtomType.NON_METAL, 7, 18, Items.CHLORINE_ATOM, 0x518141),//green
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BondManager {

Expand Down Expand Up @@ -44,7 +46,7 @@ public ItemStack getStack() {
ItemStack stack = new ItemStack(Items.BOND);
NbtCompound nbt = stack.getOrCreateNbt();
nbt.putBoolean("MinelabsBondDirection", vertical);
nbt.putInt("MinelabsBondAmount", bondCount);
nbt.putInt("MinelabsBondAmount", bondCount);
return stack;
}

Expand Down Expand Up @@ -91,4 +93,63 @@ public boolean removeBond(Bond bond) {
public void clear() {
bonds.clear();
}

public Bond getBond(Slot slot1, Slot slot2) {
for (Bond bond : bonds) {
if (bond.slot1 == slot1 && bond.slot2 == slot2
|| bond.slot1 == slot2 && bond.slot2 == slot2) {
return bond;
}
}
return null;
}

public Map<String, Integer> findEmptyBonds(Slot slot) {
Map<String, Integer> dirs = new HashMap<>(Map.of(
"n", 0,
"e", 0,
"s", 0,
"w", 0
));

for (Bond bond : bonds) {
if (bond.slot1 == slot) { // given slot is bond's slot 1
// CHECK Y
if (bond.slot1.y > bond.slot2.y) { // ABOVE
dirs.put("n", bond.bondCount);
} else if (bond.slot1.y < bond.slot2.y) { //BELOW
dirs.put("s", bond.bondCount);
} else {
// CHECK X
if (bond.slot1.x > bond.slot2.x) { // LEFT
dirs.put("w", bond.bondCount);
} else if (bond.slot1.x < bond.slot2.x) { //RIGHT
dirs.put("e", bond.bondCount);
}
}
} else if (bond.slot2 == slot) { // given slot is bond's slot 2
// CHECK Y
if (bond.slot1.y > bond.slot2.y) { // BLOW
dirs.put("s", bond.bondCount);
} else if (bond.slot1.y < bond.slot2.y) { //ABOVE
dirs.put("n", bond.bondCount);
} else {
// CHECK X
if (bond.slot1.x > bond.slot2.x) { // RIGHT
dirs.put("e", bond.bondCount);
} else if (bond.slot1.x < bond.slot2.x) { //LEFT
dirs.put("w", bond.bondCount);
}
}
}
}
return dirs;
}

public Bond getOrCreateBond(Slot slot1, Slot slot2, int bondOrder) {
if (getBond(slot1, slot2) == null) {
this.addBond(new Bond(slot1, slot2, bondOrder));
}
return getBond(slot1, slot2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package be.uantwerpen.minelabs.crafting.molecules;

import be.uantwerpen.minelabs.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ValenceElectrons {
private final int totalElectronCount;

private Map<String, Integer> directionalValence;

/**
* @param bondDirections : amount of bonds in which direction
* @param valenceE : amount of electrons on the current atom
* @param forced : True = use pairs, False = Use 1's
*/
public ValenceElectrons(Map<String, Integer> bondDirections, int valenceE, boolean forced) {
this.totalElectronCount = valenceE;
directionalValence = new HashMap<>(Map.of(
"n", 0,
"e", 0,
"s", 0,
"w", 0
));
addElectrons(bondDirections, valenceE, forced);
}

/**
* @param bondDirections : amount of bonds in which direction
* @param count : amount of electrons to place around the atom
* @param forced : True = use pairs, False = Use 1's
*/
private void addElectrons(Map<String, Integer> bondDirections, int count, boolean forced) {
//inverse bonddir & voorkeur N-E-S-W
// int: in elke richting 0,1,2
while (count > 0) {
for (String key : getBestList(bondDirections, forced)) {
if (count == 0) {
break;
}
if (bondDirections.get(key) == 0) {
if (count >= 2 && directionalValence.get(key) == 0 && forced) {
addEDir(key, 2);
count -= 2;
} else {
addEDir(key, 1);
count -= 1;
}
}
}
}
}

/**
* @param bondDirections : amount of bonds in which direction
* @param forced : True = use pairs, False = Use 1's
* @return A list contain a set order to iterate over
*/
private List<String> getBestList(Map<String, Integer> bondDirections, boolean forced) {
if (totalElectronCount > 3 || (totalElectronCount == 2 && !forced)) {
if (bondDirections.get("n") != 0 || bondDirections.get("s") != 0) {
return Arrays.asList("e", "w", "n", "s");
} else if (bondDirections.get("e") != 0 || bondDirections.get("w") != 0) {
return Arrays.asList("n", "s", "e", "w");
} else {
return Arrays.asList("n", "e", "s", "w");
}
} else {
if (bondDirections.get("n") != 0 || bondDirections.get("s") != 0) {
return Arrays.asList("n", "s", "e", "w");
} else if (bondDirections.get("e") != 0 || bondDirections.get("w") != 0) {
return Arrays.asList("e", "w", "n", "s");
} else {
return Arrays.asList("n", "e", "s", "w");
}
}
}

private void addEDir(String direction, int amount) {
directionalValence.put(direction, directionalValence.get(direction) + amount);
}

@NotNull
public ItemStack getStack(String direction) {
ItemStack stack = new ItemStack(Items.VALENCEE);
//TODO make item and overrides for model
NbtCompound nbt = stack.getOrCreateNbt();

nbt.putInt(direction, directionalValence.get(direction));

return stack;
}

public Integer getDirectionalValence(String direction) {
return directionalValence.get(direction);
}
}

61 changes: 61 additions & 0 deletions src/main/java/be/uantwerpen/minelabs/fluid/CCl4Fluid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package be.uantwerpen.minelabs.fluid;

import be.uantwerpen.minelabs.block.Blocks;
import be.uantwerpen.minelabs.item.Items;
import net.minecraft.block.BlockState;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.Item;
import net.minecraft.state.property.Properties;

public abstract class CCl4Fluid extends AbstractFluid {
@Override
public Fluid getFlowing() {
return Fluids.FLOWING_CCl4;
}

@Override
public Fluid getStill() {
return Fluids.STILL_CCl4;
}

public Item getBucketItem() {
return Items.ERLENMEYER_CCL4;
}

@Override
protected BlockState toBlockState(FluidState fluidState) {
// getBlockStateLevel converts the LEVEL_1_8 of the fluid state to the LEVEL_15 the fluid block uses
return Blocks.CCl4.getDefaultState().with(Properties.LEVEL_15, getBlockStateLevel(fluidState));
}

public static class Flowing extends CCl4Fluid {
@Override
protected void appendProperties(net.minecraft.state.StateManager.Builder<Fluid, FluidState> builder) {
super.appendProperties(builder);
builder.add(LEVEL);
}

@Override
public int getLevel(FluidState fluidState) {
return fluidState.get(LEVEL);
}

@Override
public boolean isStill(FluidState fluidState) {
return false;
}
}

public static class Still extends CCl4Fluid {
@Override
public int getLevel(FluidState fluidState) {
return 2;
}

@Override
public boolean isStill(FluidState fluidState) {
return true;
}
}
}
Loading

0 comments on commit 39f5306

Please sign in to comment.