Skip to content

Commit

Permalink
Merge pull request #29 from vrglab/dev/1.20.4
Browse files Browse the repository at this point in the history
Patch 1.0.1
  • Loading branch information
vrglab authored Jul 3, 2024
2 parents ee7dbac + 004c83f commit 612e3b1
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public static void initRegistry(ICallBack _registery, UUID _currentRegistryTypes
open_registeries.get(modid).put(_currentRegistryTypes, _registery);
}
if(ready_to_load_registeries.containsKey(modid) && ready_to_load_registeries.get(modid).size() > 0) {
VLModInfo.LOGGER.warn("Registry " +_currentRegistryTypes + " for " + modid + " has unresolved cached object's for registering, Registering objects now ");
for (UnregisteredData data: ready_to_load_registeries.get(modid)) {
if(!data.resolved && data.registry_type == _currentRegistryTypes){
VLModInfo.LOGGER.info("Registring " + _currentRegistryTypes + " " + data.args.toArray()[0] + " for " + modid);
data.Obj = _registery.accept(data.args.toArray());
data.resolved = true;
}
Expand Down Expand Up @@ -345,10 +347,12 @@ public static Object SimpleRegister(IRegistryType type, String Modid, Object...
* @since 1.1.0
*/
public static Object SimpleRegister(UUID type, String Modid, Object... args){
VLModInfo.LOGGER.info("Registering "+String.valueOf(type).toLowerCase() +" " + args[0] + " for " + Modid);
if(open_registeries.containsKey(Modid) && open_registeries.get(Modid).containsKey(type))
if(open_registeries.containsKey(Modid) && open_registeries.get(Modid).containsKey(type)) {
VLModInfo.LOGGER.info("Registering " +type + " " + args[0] + " for " + Modid);
return open_registeries.get(Modid).get(type).accept(args);
}
else {
VLModInfo.LOGGER.error("Registry "+ type + " is not yet initialized caching object " + args[0] + " in mod " + Modid + " for later registration");
UnregisteredData data = new UnregisteredData(type, args);
if(!ready_to_load_registeries.containsKey(Modid)) {
ready_to_load_registeries.put(Modid, new HashSet<>());
Expand Down
2 changes: 1 addition & 1 deletion 1.20.4/common/src/main/java/org/Vrglab/VrglabsLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public final class VrglabsLib {

public static void init() {

TestMod.init();
}
}
2 changes: 1 addition & 1 deletion 1.20.4/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

# Mod properties
loader_safe_version=1.0.0
loader_safe_version=1.0.1
maven_group = org.Vrglab
archives_name = vrglabslib
enabled_platforms = fabric,neoforge,quilt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import dev.architectury.registry.level.biome.BiomeModifications;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.entity.player.PlayerInventory;
Expand Down Expand Up @@ -33,25 +35,33 @@
import net.minecraft.world.poi.PointOfInterestType;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.loading.moddiscovery.MinecraftLocator;
import net.neoforged.neoforge.capabilities.*;
import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.common.world.BiomeModifier;
import net.neoforged.neoforge.common.world.BiomeModifiers;
import net.neoforged.neoforge.energy.IEnergyStorage;
import net.neoforged.neoforge.event.village.VillagerTradesEvent;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import org.Vrglab.EnergySystem.EnergyStorage;
import org.Vrglab.EnergySystem.EnergyStorageUtils;
import org.Vrglab.Modloader.CreationHelpers.OreGenFeatCreationHelper;
import org.Vrglab.Modloader.CreationHelpers.PlacementModifierCreationHelper;
import org.Vrglab.Modloader.CreationHelpers.TypeTransformer;
import org.Vrglab.Modloader.Registration.Bootstrapper;
import org.Vrglab.Modloader.Registration.Registry;
import org.Vrglab.Modloader.Types.IBlockEntityLoaderFunction;
import org.Vrglab.Modloader.Types.ICallbackVoid;
import org.Vrglab.Modloader.Types.IScreenHandledCreationFunction;
import org.Vrglab.Modloader.enumTypes.BootstrapType;
import org.Vrglab.Modloader.enumTypes.RegistryTypes;
import org.Vrglab.Modloader.Types.ICallBack;
import org.Vrglab.Modloader.enumTypes.VinillaBiomeTypes;
import org.Vrglab.Networking.Network;

import java.lang.reflect.Field;
import java.util.List;
import java.util.function.Supplier;

Expand All @@ -76,6 +86,17 @@ public Object accept(Object... args) {


public static void Create(IEventBus eventBus, String modid) {

TypeTransformer.ObjectToType = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((DeferredHolder)args[0]).get();
}
};
createEnergyCallBacks();
createOreGenStatics();
createNetworkStatics();

DeferredRegister<ItemGroup> ITEM_GROUP_REGISTRY = DeferredRegister.create(Registries.ITEM_GROUP.getKey(), modid);
ITEM_GROUP_REGISTRY.register(eventBus);

Expand All @@ -91,33 +112,15 @@ public static void Create(IEventBus eventBus, String modid) {
DeferredRegister<VillagerProfession> PROFESSION_REGISTRY = DeferredRegister.create(Registries.VILLAGER_PROFESSION.getKey(), modid);
PROFESSION_REGISTRY.register(eventBus);

DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPE = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE.getKey(), modid);
BLOCK_ENTITY_TYPE.register(eventBus);

DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZER_REGISTRY = DeferredRegister.create(Registries.RECIPE_SERIALIZER.getKey(), modid);
RECIPE_SERIALIZER_REGISTRY.register(eventBus);

DeferredRegister<RecipeType<?>> RECIPE_TYPE_REGISTRY = DeferredRegister.create(Registries.RECIPE_TYPE.getKey(), modid);
RECIPE_TYPE_REGISTRY.register(eventBus);

TypeTransformer.ObjectToType = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((DeferredHolder)args[0]).get();
}
};

OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((Block)((DeferredBlock)args[0]).get()).getDefaultState();
}
};

PlacementModifierCreationHelper.getHeightModifications = new ICallBack() {
@Override
public Object accept(Object... args) {
return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((Integer) args[0]), YOffset.aboveBottom((Integer) args[1]));
}
};

ICallBack Itemcallback = new ICallBack() {
@Override
public Object accept(Object... args) {
Expand Down Expand Up @@ -176,6 +179,13 @@ public Object accept(Object... args) {
}
};

ICallBack BlockEntityTypeRegistryCallBack = new ICallBack() {
@Override
public Object accept(Object... args) {
return BLOCK_ENTITY_TYPE.register(args[0].toString(), ()->BlockEntityType.Builder.create((blockPos,blockState)->((IBlockEntityLoaderFunction)args[1]).create(blockPos, blockState), ((Block)((DeferredBlock)args[2]).get())).build(null));
}
};

ICallBack RecipeSerializerRegistryCallBack = new ICallBack() {
@Override
public Object accept(Object... args) {
Expand All @@ -201,6 +211,7 @@ public Object accept(Object... args) {
Registry.initRegistry(Itemcallback, RegistryTypes.ITEM, modid);
Registry.initRegistry(ItemlessBlockcallback, RegistryTypes.ITEMLESS_BLOCK, modid);
Registry.initRegistry(Blockcallback, RegistryTypes.BLOCK, modid);
Registry.initRegistry(BlockEntityTypeRegistryCallBack, RegistryTypes.BLOCK_ENTITY_TYPE, modid);
Registry.initRegistry(POIcallback, RegistryTypes.POI, modid);
Registry.initRegistry(Professioncallback, RegistryTypes.PROFESSION, modid);
Registry.initRegistry(OreGenRegistryCallBack, RegistryTypes.CONFIGURED_FEAT_ORE, modid);
Expand Down Expand Up @@ -243,4 +254,146 @@ public static void boostrap(RegistryBuilder builder, String modid) {
return r.register((RegistryKey<PlacedFeature>)args[0], new PlacedFeature(config_feat_lookup.getOrThrow((RegistryKey<ConfiguredFeature<?, ?>>) args[1]), (List<PlacementModifier>)args[2]));
}, BootstrapType.PLACED_FEAT, modid));
}

private static void createEnergyCallBacks() {
EnergyStorageUtils.createStorageInstance = new ICallBack() {
@Override
public Object accept(Object... args) {
return new net.neoforged.neoforge.energy.EnergyStorage(Math.toIntExact((long)args[0]), Math.toIntExact((long)args[1]), Math.toIntExact((long)args[2]), Math.toIntExact((long)args[3])) {
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
try {
((EnergyStorage)args[4]).makeDirty.accept();
} catch (Throwable t) {

}
return super.receiveEnergy(maxReceive, simulate);
}

@Override
public int extractEnergy(int maxExtract, boolean simulate) {
try {
((EnergyStorage)args[4]).makeDirty.accept();
} catch (Throwable t) {

}
return super.extractEnergy(maxExtract, simulate);
}
};
}
};

EnergyStorageUtils.receiveEnergyInstance = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((net.neoforged.neoforge.energy.IEnergyStorage)args[0]).receiveEnergy(Math.toIntExact((long)args[1]), (boolean)args[2]);
}
};

EnergyStorageUtils.extractEnergyInstance = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((net.neoforged.neoforge.energy.IEnergyStorage)args[0]).extractEnergy(Math.toIntExact((long)args[1]), (boolean)args[2]);
}
};

EnergyStorageUtils.hasExternalStorage = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((((BlockEntity)args[0]) != null) && ((BlockEntity)args[0]) instanceof ICapabilityProvider)||((((BlockEntity)args[0]) != null) && ((BlockCapability)args[0]).getCapability(((BlockEntity)args[0]).getWorld(), ((BlockEntity)args[0]).getPos(), ((BlockEntity)args[0]).getCachedState(), ((BlockEntity)args[0]), Capabilities.EnergyStorage.BLOCK) != null);
}
};

EnergyStorageUtils.wrapExternalStorage = new ICallBack() {
@Override
public Object accept(Object... args) {
net.neoforged.neoforge.energy.IEnergyStorage storage = (IEnergyStorage)((BlockCapability)args[3]).getCapability(((BlockEntity)args[0]).getWorld(), ((BlockEntity)args[0]).getPos(), ((BlockEntity)args[0]).getCachedState(), ((BlockEntity)args[0]), Capabilities.EnergyStorage.BLOCK);
Field maxReceiveField = null;
try {
maxReceiveField = storage.getClass().getDeclaredField("maxReceive");
} catch (NoSuchFieldException e) {

}
int maxReceive = 0;
maxReceiveField.setAccessible(true);
try {
maxReceive = (int) maxReceiveField.get(storage);
} catch (IllegalAccessException e) {

}
Field maxExtractField = null;
try {
maxExtractField = storage.getClass().getDeclaredField("maxExtract");
} catch (NoSuchFieldException e) {

}
maxExtractField.setAccessible(true);
int maxExtract = 0;
try {
maxExtract = (int) maxExtractField.get(storage);
} catch (IllegalAccessException e) {

}
Field capacityField = null;
try {
capacityField = storage.getClass().getDeclaredField("capacity");
} catch (NoSuchFieldException e) {

}
capacityField.setAccessible(true);
int capacity = 0;
try {
capacity = (int) capacityField.get(storage);
} catch (IllegalAccessException e) {

}
Field energyField = null;
try {
energyField = storage.getClass().getDeclaredField("energy");
} catch (NoSuchFieldException e) {
}
energyField.setAccessible(true);
int energy = 0;
try {
energy = (int) energyField.get(storage);
} catch (IllegalAccessException e) {

}
return new EnergyStorage(storage, capacity, maxReceive, maxExtract, energy).setBlockEntityType(((BlockEntity)args[3])).setMakeDirtyFunction(()->((BlockEntity)args[3]).markDirty());
}
};
}

private static void createOreGenStatics() {

OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() {
@Override
public Object accept(Object... args) {
return ((Block)((DeferredBlock)args[0]).get()).getDefaultState();
}
};

PlacementModifierCreationHelper.getHeightModifications = new ICallBack() {
@Override
public Object accept(Object... args) {
return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((Integer) args[0]), YOffset.aboveBottom((Integer) args[1]));
}
};
}

private static void createNetworkStatics() {
Network.registerGlobalReceiver = new ICallbackVoid() {
@Override
public void accept(Object... args) {

}
};

Network.clientSendPacket = new ICallbackVoid() {
@Override
public void accept(Object... args) {

}
};
}
}
Loading

0 comments on commit 612e3b1

Please sign in to comment.