Skip to content

Commit

Permalink
allow transmitters to cross-dimensions; add examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Apr 2, 2024
1 parent 466abb3 commit 6690949
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 39 deletions.
File renamed without changes.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,23 @@ dependencies {

implementation fg.deobf("mezz.jei:${jei_version}")
implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}")
implementation fg.deobf("com.blamejared.crafttweaker:CraftTweaker-${mc_version}:${crafttweaker_version}")

compileOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}:api")
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}")

compileOnly fg.deobf("vazkii.botania:Botania:${botania_version}:api")
runtimeOnly fg.deobf("vazkii.botania:Botania:${botania_version}")

/*
implementation fg.deobf("com.blamejared.crafttweaker:CraftTweaker-${mc_version}:${crafttweaker_version}")
// optional dependencies & mods for testing compat

implementation fg.deobf("curse.maven:mantle-74924:3482897")
implementation fg.deobf("curse.maven:tinkers-construct-74072:3482903")
implementation fg.deobf("curse.maven:cucumber-272335:3507886")
implementation fg.deobf("curse.maven:mystical-agriculture-246640:3562127")
implementation fg.deobf("curse.maven:chunknogobyebye-332695:3195333")
*/


// To use any mod in /libs/ folder, place it in and set the mod and version to match jar filename
// runtimeOnly fg.deobf("libs:SimpleStorageNetwork:1.16.4-1.3.1")
// runtimeOnly fg.deobf("libs:refinedstorage:1.16.4-1.9.11")
Expand Down
2 changes: 1 addition & 1 deletion cyclic-client.toml → examples/config/cyclic-client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[cyclic.blocks.text]
#True means this will hide the fluid contents chat message (right click) on relevant blocks (pylon, fluid generator, fluid hopper, solidifier, sprinkler, tank, cask)
FluidContents = false
FluidContents = true

[cyclic.blocks.colors]
#Specify hex color of preview mode. default #00EE00
Expand Down
2 changes: 2 additions & 0 deletions cyclic.toml → examples/config/cyclic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
# Block specific configs
#####################################################################################
[cyclic.blocks]
# Allows the dimensional Transfer Nodes to cross dimensions (no chunk loading is done, you have to do that on your own); This affects blocks cyclic:wireless_energy, cyclic:wireless_item, cyclic:wireless_fluid, cyclic:wireless_transmitter; If you change it to false it will only work if the target is in the same dimension.
wireless_transfer_dimensional = true

#Ender shelf settings
[cyclic.blocks.ender_shelf]
Expand Down
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 52 additions & 10 deletions src/main/java/com/lothrazar/cyclic/base/TileEntityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.lothrazar.cyclic.block.breaker.BlockBreaker;
import com.lothrazar.cyclic.block.cable.energy.TileCableEnergy;
import com.lothrazar.cyclic.capability.CustomEnergyStorage;
import com.lothrazar.cyclic.data.BlockPosDim;
import com.lothrazar.cyclic.item.datacard.filter.FilterCardItem;
import com.lothrazar.cyclic.net.PacketEnergySync;
import com.lothrazar.cyclic.registry.PacketRegistry;
Expand Down Expand Up @@ -257,7 +258,14 @@ public boolean requiresRedstone() {
return this.needsRedstone == 1;
}

public void moveFluids(Direction myFacingDir, BlockPos posTarget, int toFlow, IFluidHandler tank) {
protected void moveFluidsDimensional(BlockPosDim loc, int toFlow, IFluidHandler tank) {
Direction myFacingDir = loc.getSide();
final Direction themFacingMe = myFacingDir.getOpposite();
// moveFluidsInternal is just util tryFillPositionFromTank
UtilFluid.tryFillPositionFromTank(loc.getServerLevel(world.getServer()), loc.getPos(), themFacingMe, tank, toFlow);
}

protected void moveFluids(Direction myFacingDir, BlockPos posTarget, int toFlow, IFluidHandler tank) {
if (tank == null || tank.getFluidInTank(0).isEmpty()) {
return;
}
Expand Down Expand Up @@ -358,18 +366,29 @@ public boolean moveItems(Direction myFacingDir, int max, IItemHandler handlerHer
return moveItems(myFacingDir, pos.offset(myFacingDir), max, handlerHere, 0);
}

public boolean moveItemsDimensional(BlockPosDim loc, int max, IItemHandler handlerHere, int theslot) {
Direction myFacingDir = loc.getSide();
final Direction themFacingMe = myFacingDir.getOpposite();
ServerWorld serverWorld = loc.getServerLevel(world.getServer());
return moveItemsInternal(max, handlerHere, theslot, themFacingMe, serverWorld.getTileEntity(loc.getPos()));
}

public boolean moveItems(Direction myFacingDir, BlockPos posTarget, int max, IItemHandler handlerHere, int theslot) {
if (max <= 0 || this.world.isRemote() || handlerHere == null) {
if (max <= 0 || this.world.isRemote()) {
return false;
}
//first get the original ItemStack as creating new ones is expensive
final ItemStack originalItemStack = handlerHere.getStackInSlot(theslot);
if (originalItemStack.isEmpty()) {
return false;
}
final Direction themFacingMe = myFacingDir.getOpposite();
final TileEntity tileTarget = world.getTileEntity(posTarget);
if (tileTarget == null) {
return moveItemsInternal(max, handlerHere, theslot, themFacingMe, tileTarget);
}

private static boolean moveItemsInternal(int max, IItemHandler handlerHere, int theslot, final Direction themFacingMe, final TileEntity tileTarget) {
if (max <= 0 || tileTarget == null || handlerHere == null) {
return false;
}
final ItemStack originalItemStack = handlerHere.getStackInSlot(theslot);
if (originalItemStack.isEmpty()) {
return false;
}
final IItemHandler handlerOutput = tileTarget.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, themFacingMe).orElse(null);
Expand Down Expand Up @@ -401,19 +420,41 @@ protected boolean moveEnergy(Direction myFacingDir, int quantity) {
return moveEnergy(myFacingDir, pos.offset(myFacingDir), quantity);
}

protected boolean moveEnergy(final Direction myFacingDir, final BlockPos posTarget, final int quantity) {
protected boolean moveEnergyDimensional(final BlockPosDim loc, final int quantity) {
//validation pre-move
if (quantity <= 0) {
return false;
}
if (this.world.isRemote) {
return false; //important to not desync cables
}
Direction myFacingDir = loc.getSide();
final IEnergyStorage handlerHere = this.getCapability(CapabilityEnergy.ENERGY, myFacingDir).orElse(null);
if (handlerHere == null) {
ServerWorld serverWorld = loc.getServerLevel(world.getServer());
final TileEntity tileTarget = serverWorld.getTileEntity(loc.getPos());
final Direction themFacingMe = myFacingDir.getOpposite();
return moveEnergyInternal(quantity, handlerHere, themFacingMe, tileTarget);
}

//assums posTarget is in the same dimension as this.world
protected boolean moveEnergy(final Direction myFacingDir, final BlockPos posTarget, final int quantity) {
//validation pre-move
if (quantity <= 0) {
return false;
}
if (this.world.isRemote) {
return false; //important to not desync cables
}
final IEnergyStorage handlerHere = this.getCapability(CapabilityEnergy.ENERGY, myFacingDir).orElse(null);
final Direction themFacingMe = myFacingDir.getOpposite();
final TileEntity tileTarget = world.getTileEntity(posTarget);
return moveEnergyInternal(quantity, handlerHere, themFacingMe, tileTarget);
}

private static boolean moveEnergyInternal(final int quantity, final IEnergyStorage handlerHere, final Direction themFacingMe, final TileEntity tileTarget) {
if (handlerHere == null) {
return false;
}
if (tileTarget == null) {
return false;
}
Expand All @@ -425,7 +466,8 @@ protected boolean moveEnergy(final Direction myFacingDir, final BlockPos posTarg
if (capacity <= 0) {
return false;
}
//first simulate
//validation is done
//next, simulate
final int drain = handlerHere.extractEnergy(Math.min(quantity, capacity), true);
if (drain <= 0) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.capability.CustomEnergyStorage;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.data.BlockPosDim;
import com.lothrazar.cyclic.item.datacard.LocationGpsCard;
import com.lothrazar.cyclic.registry.TileRegistry;
Expand Down Expand Up @@ -100,8 +101,15 @@ public void tick() {
boolean moved = false;
//run the transfer. one slot only
BlockPosDim loc = getTargetInSlot(0);
if (loc != null && UtilWorld.dimensionIsEqual(loc, world)) {
moved = moveEnergy(Direction.UP, loc.getPos(), transferRate);
if (loc != null) {
if (UtilWorld.dimensionIsEqual(loc, world)) {
// assume position is in the same level/dimension/world
moved = moveEnergy(loc.getSide(), loc.getPos(), transferRate);
}
else if (ConfigRegistry.TRANSFER_NODES_DIMENSIONAL.get()) {
//allows config to disable this cross dimension feature for modpack balance purposes
moved = moveEnergyDimensional(loc, transferRate);
}
}
this.setLitProperty(moved);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lothrazar.cyclic.base.FluidTankBase;
import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.data.BlockPosDim;
import com.lothrazar.cyclic.item.datacard.LocationGpsCard;
import com.lothrazar.cyclic.registry.TileRegistry;
Expand Down Expand Up @@ -115,8 +116,13 @@ public void tick() {
boolean moved = false;
//run the transfer. one slot only
BlockPosDim loc = getTargetInSlot(0);
if (loc != null && UtilWorld.dimensionIsEqual(loc, world)) {
this.moveFluids(loc.getSide(), loc.getPos(), this.transferRate, tank);
if (loc != null) {
if (UtilWorld.dimensionIsEqual(loc, world)) {
this.moveFluids(loc.getSide(), loc.getPos(), this.transferRate, tank);
}
else if (ConfigRegistry.TRANSFER_NODES_DIMENSIONAL.get()) {
this.moveFluidsDimensional(loc, this.transferRate, tank);
}
}
this.setLitProperty(moved);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lothrazar.cyclic.block.wireless.item;

import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.data.BlockPosDim;
import com.lothrazar.cyclic.item.datacard.LocationGpsCard;
import com.lothrazar.cyclic.registry.TileRegistry;
Expand Down Expand Up @@ -98,8 +99,13 @@ public void tick() {
boolean moved = false;
//run the transfer. one slot only
BlockPosDim loc = getTargetInSlot();
if (loc != null && UtilWorld.dimensionIsEqual(loc, world)) {
moved = moveItems(Direction.UP, loc.getPos(), this.transferRate, this.inventory, 0);
if (loc != null) {
if (UtilWorld.dimensionIsEqual(loc, world)) {
moved = moveItems(loc.getSide(), loc.getPos(), this.transferRate, this.inventory, 0);
}
else if (ConfigRegistry.TRANSFER_NODES_DIMENSIONAL.get()) {
moved = moveItemsDimensional(loc, this.transferRate, this.inventory, 0);
}
}
this.setLitProperty(moved);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lothrazar.cyclic.ModCyclic;
import com.lothrazar.cyclic.base.TileEntityBase;
import com.lothrazar.cyclic.config.ConfigRegistry;
import com.lothrazar.cyclic.data.BlockPosDim;
import com.lothrazar.cyclic.item.datacard.LocationGpsCard;
import com.lothrazar.cyclic.registry.TileRegistry;
Expand Down Expand Up @@ -97,11 +98,11 @@ public CompoundNBT write(CompoundNBT tag) {

@SuppressWarnings("deprecation")
private void toggleTarget(BlockPosDim dimPos) {
if (world.isRemote) {
if (dimPos == null || world.isRemote) {
return;
}
BlockPos targetPos = dimPos.getPos();
ServerWorld serverLevel = world.getServer().getWorld(UtilWorld.stringToDimension(dimPos.getDimension()));
ServerWorld serverLevel = dimPos.getServerLevel(world.getServer()); // world.getServer().getWorld(UtilWorld.stringToDimension(dimPos.getDimension()));
if (serverLevel == null) {
ModCyclic.LOGGER.info("Dimension not found " + dimPos.getDimension());
return;
Expand All @@ -111,41 +112,30 @@ private void toggleTarget(BlockPosDim dimPos) {
return;
}
boolean isPowered = world.isBlockPowered(pos);
// BlockState target = serverLevel.getBlockState(targetPos);
if (serverLevel.getTileEntity(targetPos) instanceof TileWirelessRec) {
TileWirelessRec receiver = (TileWirelessRec) serverLevel.getTileEntity(targetPos);
//am I powered?
if (isPowered) {
// ModCyclic.LOGGER.info(" POWER UP target" + dimPos);
receiver.putPowerSender(this.id);
}
else {
// ModCyclic.LOGGER.info(" turn off target" + dimPos);
receiver.removePowerSender(this.id);
}
}
world.setBlockState(pos, world.getBlockState(pos).with(BlockStateProperties.POWERED, isPowered));
// if (target.hasProperty(BlockStateProperties.POWERED)) {
// boolean targetPowered = target.get(BlockStateProperties.POWERED);
// //update target based on my state
// boolean isPowered = world.isBlockPowered(pos);
// if (targetPowered != isPowered) {
// serverLevel.setBlockState(targetPos, target.with(BlockStateProperties.POWERED, isPowered));
// //and update myself too
// world.setBlockState(pos, world.getBlockState(pos).with(BlockStateProperties.POWERED, isPowered));
// //TODO: send exact 1-16 power level
// // world.getTileEntity(targetPos) instanceof TileWirelessRec
// // && target.getBlock() instanceof BlockWirelessRec
// }
// }
}

@Override
public void tick() {
for (int s = 0; s < inventory.getSlots(); s++) {
BlockPosDim targetPos = getTargetInSlot(s);
if (targetPos == null ||
UtilWorld.dimensionIsEqual(targetPos, world) == false) {
if (!UtilWorld.dimensionIsEqual(targetPos, world) && !ConfigRegistry.TRANSFER_NODES_DIMENSIONAL.get()) {
//if dimensions dont match, AND config disables x-dimension communication, then skip this one
continue;
}
//else gogogo
toggleTarget(targetPos);
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/lothrazar/cyclic/config/ConfigRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public class ConfigRegistry {
public static BooleanValue COMMANDHUNGER;
public static BooleanValue COMMANDPING;
public static BooleanValue LOGINFO;
public static BooleanValue TRANSFER_NODES_DIMENSIONAL;
public static IntValue HEARTXPMINUS;
private static ConfigValue<List<? extends String>> BEHEADING_SKINS;
private static ConfigValue<List<? extends String>> MBALL_IGNORE_LIST;
Expand Down Expand Up @@ -384,6 +385,11 @@ private static void initConfig() {
CFG.pop(); //items
CFG.comment(WALL, " Block specific configs", WALL)
.push("blocks");
TRANSFER_NODES_DIMENSIONAL = CFG.comment(" Allows the dimensional Transfer Nodes to cross dimensions "
+ "(no chunk loading is done, you have to do that on your own); "
+ "This affects blocks cyclic:wireless_energy, cyclic:wireless_item, cyclic:wireless_fluid, cyclic:wireless_transmitter; "
+ "If you change it to false it will only work if the target is in the same dimension.")
.define("wireless_transfer_dimensional", true);
CFG.comment("Ender shelf settings").push("sound");
BlockSoundRecorder.RADIUS = CFG.comment("Sound Recorder - how far out does it listen to record sounds").defineInRange("radius", 8, 1, 64);
CFG.pop();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/lothrazar/cyclic/data/BlockPosDim.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.lothrazar.cyclic.data;

import com.lothrazar.cyclic.util.UtilWorld;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.server.ServerWorld;

public class BlockPosDim {

Expand Down Expand Up @@ -112,4 +115,8 @@ public BlockPos getPos() {
public void setPos(BlockPos pos) {
this.pos = pos;
}

public ServerWorld getServerLevel(MinecraftServer server) {
return server.getWorld(UtilWorld.stringToDimension(this.getDimension()));
}
}

0 comments on commit 6690949

Please sign in to comment.