This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
754 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/me/oganesson/gregica/api/capability/fluid/InfFluidTank.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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
15
src/main/java/me/oganesson/gregica/api/data/CrossWorldData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/me/oganesson/gregica/common/data/CWDataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/me/oganesson/gregica/common/data/CrossWorldDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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."); | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/me/oganesson/gregica/common/data/DataEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} | ||
|
||
|
||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/me/oganesson/gregica/common/recipes/xkball/XkballRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.