Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
无限水仓 语言工具 跨维度数据(未完成)
Browse files Browse the repository at this point in the history
  • Loading branch information
xkball committed Jun 6, 2023
1 parent 9f609c9 commit 9789ae3
Show file tree
Hide file tree
Showing 28 changed files with 754 additions and 99 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.daemon=false
## mod info
archives_base_name=Gregica++
minecraft_version=1.12.2
current_version=0.0.3
current_version=0.4.3
current_state=alpha

## Hard Dependensies
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/me/oganesson/gregica/GCEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import me.oganesson.gregica.common.unification.materials.ore.GCOrePrefixs;
import me.oganesson.gregica.network.GCNetworkManager;
import me.oganesson.gregica.network.packets.MouseEventToSeverPacker;
import me.oganesson.gregica.utils.GCLangUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand All @@ -24,6 +25,7 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -85,4 +87,10 @@ public static void initMaterialInfo(GregTechAPI.RegisterEvent<ItemMaterialInfo>
public static void initComponents(GregTechAPI.RegisterEvent<CraftingComponent> event) {
GCYSCraftingComponent.init();
}

@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onClientEvent(TickEvent.ClientTickEvent event){
GCLangUtil.updateModifier();
}
}
9 changes: 7 additions & 2 deletions src/main/java/me/oganesson/gregica/Gregica.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.oganesson.gregica;

import gregtech.common.ConfigHolder;
import gregtech.api.event.HighTierEvent;
import me.oganesson.gregica.client.render.BlocksHighlightRenderer;
import me.oganesson.gregica.proxy.CommonProxy;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -42,7 +42,7 @@ public class Gregica {

@EventHandler
public void onConstruction(FMLConstructionEvent event) {
ConfigHolder.machines.highTierContent = true;
// ConfigHolder.machines.highTierContent = true;
}

@EventHandler
Expand All @@ -66,6 +66,11 @@ public static ResourceLocation gcResource(String path){
@Mod.EventBusSubscriber
public static class ObjectRegistryHandler {
/** Listen for the register event for creating custom items */

@SubscribeEvent
public static void onCheckHighTier(HighTierEvent event){
event.enableHighTier();
}
@SubscribeEvent
public static void addItems(RegistryEvent.Register<Item> event) {
proxy.registerItems(event);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/me/oganesson/gregica/api/GCValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class GCValues {

public static final boolean IS_TC_LOADED = Loader.isModLoaded("thaumcraft");

@SuppressWarnings("SpellCheckingInspection")
public static final boolean IS_BilingualName_LOADED = Loader.isModLoaded("bilingualname");

//用于writeCustomData
public static final int UPDATE_TIER = 114514;
public static final int REQUIRE_DATA_UPDATE = 1919;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package me.oganesson.gregica.api.capability.fluid;

import gregtech.api.capability.impl.NotifiableFluidTank;
import gregtech.api.metatileentity.MetaTileEntity;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.Nullable;

public class InfFluidTank extends NotifiableFluidTank {

final Fluid fluidType;
final FluidStack stack;

public InfFluidTank(FluidStack fluidStack, MetaTileEntity entityToNotify, boolean isExport) {
super(Integer.MAX_VALUE, entityToNotify, isExport);
this.fluid = fluidStack;
this.fluidType = fluidStack.getFluid();
this.stack = new FluidStack(fluid,Integer.MAX_VALUE);
}

@Nullable
@Override
public FluidStack getFluid() {
return stack;
}

@Override
public void setFluid(@Nullable FluidStack fluid) {
}

public void update(){
this.onContentsChanged();
}
@Override
public boolean canFill() {
return false;
}

@Override
public boolean canDrain() {
return true;
}

@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
return resource;
}

@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
if(fluid != null){
return new FluidStack(fluid,maxDrain);
}
return null;
}

@Override
public int fill(FluidStack resource, boolean doFill) {
return 0;
}

@Override
public int getFluidAmount() {
return Integer.MAX_VALUE;
}
}
15 changes: 15 additions & 0 deletions src/main/java/me/oganesson/gregica/api/data/CrossWorldData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.oganesson.gregica.api.data;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IStringSerializable;

public interface CrossWorldData extends IStringSerializable {

void load(NBTTagCompound tagCompound);

NBTTagCompound save();

boolean isDirty();

void init();
}
9 changes: 6 additions & 3 deletions src/main/java/me/oganesson/gregica/client/GCTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class GCTextures {

public static SimpleOverlayRenderer LASER_COLORED;

public static SimpleOverlayRenderer INF_WATER;

public static SimpleSidedCubeRenderer LAPOTRONIC_CASING;

public static OrientedOverlayRenderer LAPOTRONIC_CAPACITOR;
Expand Down Expand Up @@ -80,9 +82,9 @@ public class GCTextures {
public static OrientedOverlayRenderer SONICATOR_OVERLAY = new OrientedOverlayRenderer("multiblock/sonicator");
public static OrientedOverlayRenderer CATALYTIC_REFORMER_OVERLAY = new OrientedOverlayRenderer("multiblock/catalytic_reformer");
public static OrientedOverlayRenderer INDUSTRIAL_DRILL_OVERLAY = new OrientedOverlayRenderer("multiblock/industrial_drill");
public static OrientedOverlayRenderer SUPRACHRONAL_OVERLAY = new OrientedOverlayRenderer("multiblock/suprachronal_assembler");

public static SimpleOverlayRenderer SUPRACHRONAL_CASING = new SimpleOverlayRenderer("casings/solid/suprachronal_casing");
// public static OrientedOverlayRenderer SUPRACHRONAL_OVERLAY = new OrientedOverlayRenderer("multiblock/suprachronal_assembler");
//
// public static SimpleOverlayRenderer SUPRACHRONAL_CASING = new SimpleOverlayRenderer("casings/solid/suprachronal_casing");


public static void preInit() {
Expand Down Expand Up @@ -113,6 +115,7 @@ public static void preInit() {
FLOTATION_CELL_REGULATOR = new SimpleOverlayRenderer("flotation_casing");
VACUUM_CASING = new SimpleOverlayRenderer("vacuum_casing");
LASER_COLORED = new SimpleOverlayRenderer("multipart/laser_hatch_colored");
INF_WATER = new SimpleOverlayRenderer("multipart/inf_water");
}

}
50 changes: 50 additions & 0 deletions src/main/java/me/oganesson/gregica/common/data/CWDataType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package me.oganesson.gregica.common.data;

import me.oganesson.gregica.api.data.CrossWorldData;

import java.util.HashMap;
import java.util.Map;

public enum CWDataType {

;
private final String name;
private final Class<? extends CrossWorldData> aClass;

private static final Map<String, CWDataType> tableMap = new HashMap<>();

CWDataType(String name, Class<? extends CrossWorldData> aClass) {
this.name = name;
this.aClass = aClass;

}

public static CrossWorldData byName(String s){
if(tableMap.isEmpty()){
for(CWDataType table : CWDataType.values()){
tableMap.put(table.name,table);
}
}
if(tableMap.containsKey(s)){
return tableMap.get(s).newInstance();
}
return null;
}

public String getName() {
return name;
}

public Class<?> getaClass() {
return aClass;
}

public CrossWorldData newInstance() {
try {
return (CrossWorldData) this.getaClass().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package me.oganesson.gregica.common.data;

import codechicken.lib.util.DirectoryWalker;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import me.oganesson.gregica.api.data.CrossWorldData;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraftforge.common.DimensionManager;

import java.io.File;
import java.io.IOException;
import java.util.Map;

public enum CrossWorldDataHandler {
INSTANCE;

private static File dataFold;

private final Map<String,CrossWorldData> data = new Object2ObjectOpenHashMap<>();
private int loadStack = 0;

public CrossWorldData getOrCreate(CWDataType type){
if(data.containsKey(type.getName())){
return data.get(type.getName());
}
CrossWorldData result = type.newInstance();
if (result != null) {
result.init();
}
return result;
}

public CrossWorldData getData(String key){
return data.get(key);
}

public void loadWorld(int dimension) throws IOException {
if(this.loadStack == 0){
DirectoryWalker walker = new DirectoryWalker(DirectoryWalker.FALSE,DirectoryWalker.TRUE);
for(File file : walker.walk(dataFold)){
CrossWorldData crossWorldData = CWDataType.byName(file.getName());
if(crossWorldData != null){
crossWorldData.load(CompressedStreamTools.read(file));
}
else {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
}
}
this.loadStack++;
}

public void unloadWorld(int dimension) throws IOException {
this.loadStack--;
if(this.loadStack <= 0){
for(CrossWorldData crossWorldData : data.values()){
File file = new File(dataFold,crossWorldData.getName());
if(!file.exists()){
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
CompressedStreamTools.safeWrite(crossWorldData.save(),file);
}
}
this.data.clear();
((Object2ObjectOpenHashMap<?, ?>)this.data).trim();
}
}

public void save(int dimension) throws IOException {
for(CrossWorldData crossWorldData : data.values()){
if(crossWorldData.isDirty()){
File file = new File(dataFold,crossWorldData.getName());
if(!file.exists()){
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
CompressedStreamTools.safeWrite(crossWorldData.save(),file);
}
}
}
}

public int getLoadStack() {
return loadStack;
}

public void setLoadStack(int loadStack) {
this.loadStack = loadStack;
}


static {
dataFold = DimensionManager.getCurrentSaveRootDirectory();
if(dataFold != null){
dataFold = new File(dataFold,"gregica_data");
if(!dataFold.exists()){
//noinspection ResultOfMethodCallIgnored
dataFold.mkdirs();
}
}
else {
throw new RuntimeException("Gregica cannot get data directory.");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.oganesson.gregica.common.data;

import me.oganesson.gregica.Gregica;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.io.IOException;

@Mod.EventBusSubscriber(modid = Gregica.MOD_ID)
public class DataEventHandler {

@SubscribeEvent
public static void onWorldLoad(WorldEvent.Load event){
try {
CrossWorldDataHandler.INSTANCE.loadWorld(event.getWorld().provider.getDimension());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@SubscribeEvent
public static void onWorldSave(WorldEvent.Save event) throws IOException {
CrossWorldDataHandler.INSTANCE.save(event.getWorld().provider.getDimension());
}

@SubscribeEvent
public static void onWorldUnload(WorldEvent.Unload event){
try {
CrossWorldDataHandler.INSTANCE.unloadWorld(event.getWorld().provider.getDimension());
} catch (IOException e) {
throw new RuntimeException(e);
}
}


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package me.oganesson.gregica.common.recipes.xkball;

import me.oganesson.gregica.common.recipes.xkball.laser.LaserRecipes;
import me.oganesson.gregica.common.recipes.xkball.worktablerecipe.XkballCraftingTableRecipe;

public class XkballRecipe {
public static void init(){
LaserRecipes.init();
XkballCraftingTableRecipe.init();
}
}
Loading

0 comments on commit 9789ae3

Please sign in to comment.