Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine Ownership #1970

Merged
merged 15 commits into from
Sep 29, 2024
6 changes: 6 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ dependencies {
modImplementation(forge.javd) { transitive = false }
modRuntimeOnly("curse.maven:trenzalore-870210:4848244")

modCompileOnly(forge.ftbteams)
modCompileOnly(forge.ftblibrary)

modCompileOnly(forge.argonauts)
modCompileOnly(forge.resourceful)

// Runtime only testing mods
//modRuntimeOnly(forge.worldStripper)
}
20 changes: 18 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencyResolutionManagement {
def auVersion = "1.20.1-0.6.0"

// Forge
def forgeVersion = "47.1.3"
def forgeVersion = "47.1.47"
def registrateForgeVersion = "MC1.20-1.3.3"
def createForgeVersion = "0.5.1.f-33"
def flywheelForgeVersion = "0.6.10-10"
Expand All @@ -44,6 +44,10 @@ dependencyResolutionManagement {
def curiosForgeVersion = "5.9.1"
def worldStripperForgeFile = "4578579"
def javdVersion = "4803995"
def ftbteamsForgeFile = "5267190"
def ftblibraryForgeFile = "5567591"
def argonautsForgeFile = "5263580"
def resourcefulForgeFile = "5659871"

// Libs
def quiltMappingsVersion = "5" // https://lambdaurora.dev/tools/import_quilt.html
Expand All @@ -58,7 +62,7 @@ dependencyResolutionManagement {
def mixinextrasVersion = "0.2.0"
def shimmerVersion = "0.2.4"
def lombokPluginVersion = "8.7.1"

forge {
version("forgeShortVersion", forgeVersion)
def minecraftForge = version("minecraftForge", "${minecraftVersion}-${forgeVersion}")
Expand Down Expand Up @@ -125,6 +129,18 @@ dependencyResolutionManagement {

def javd = version("javd", javdVersion)
library("javd", "curse.maven", "javd-370890").versionRef(javd)

def ftbteams = version("ftbteams", ftbteamsForgeFile)
library("ftbteams", "curse.maven", "ftb-teams-forge-404468").versionRef(ftbteams)

def ftblibrary = version("ftblibrary", ftblibraryForgeFile)
library("ftblibrary", "curse.maven", "ftb-library-forge-404465").versionRef(ftblibrary)

def argonautslib = version("argonauts", argonautsForgeFile)
library("argonauts", "curse.maven", "argonauts-845833").versionRef(argonautslib)

def resourceful = version("resourceful", resourcefulForgeFile)
library("resourceful", "curse.maven", "resourceful-lib-570073").versionRef(resourceful)
}

libs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"res": "gtceu:aluminium_frame"
},
"items": [
"#forge:frames",
"#minecraft:climbable"
"#minecraft:climbable",
"#forge:frames"
],
"page": "gtceu:materials/frame",
"position": [
Expand Down
6 changes: 6 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"behavior.portable_scanner.environmental_hazard": "ɯdd %s - ɹ§%s :ʞunɥƆ uI pɹɐzɐH ןɐʇuǝɯuoɹıʌuƎ",
"behavior.portable_scanner.environmental_hazard.nothing": "ɹ§buıɥʇoN9§ :ʞunɥƆ uI pɹɐzɐH ןɐʇuǝɯuoɹıʌuƎ",
"behavior.portable_scanner.eu_per_sec": "ʇ/∩Ǝ %s :)puoɔǝs ʇsɐן( ǝbɐɹǝʌⱯ",
"behavior.portable_scanner.guild_name": "ɹ§%s :ǝɯɐN pןın⅁ᄅ§",
"behavior.portable_scanner.local_hazard": "ɯdd %s - ɹ§%s :ɐǝɹⱯ uI pɹɐzɐH ןɐɔoꞀ",
"behavior.portable_scanner.local_hazard.nothing": "ɹ§buıɥʇoN9§ :ɐǝɹⱯ uI pɹɐzɐH ןɐɔoꞀ",
"behavior.portable_scanner.machine_disabled": "˙pǝןqɐsıᗡ",
"behavior.portable_scanner.machine_front_facing": "%s :buıɔɐℲ ʇuoɹℲ",
"behavior.portable_scanner.machine_ownership": "ɹ§%s :ǝdʎ⟘ ɹǝuʍO ǝuıɥɔɐWᄅ§",
"behavior.portable_scanner.machine_power_loss": "˙ssoן ɹǝʍod oʇ ǝnp uʍop ʇnɥS",
"behavior.portable_scanner.machine_progress": "%s / %s :pɐoꞀ/ssǝɹboɹԀ",
"behavior.portable_scanner.machine_upwards_facing": "%s :buıɔɐℲ spɹɐʍd∩",
Expand All @@ -42,10 +44,12 @@
"behavior.portable_scanner.multiblock_energy_output": "%s :ɹǝı⟘ ʇ/∩Ǝ %s :ʇndʇnO ʎbɹǝuƎ xɐW",
"behavior.portable_scanner.multiblock_maintenance": "%s :sɯǝןqoɹԀ",
"behavior.portable_scanner.multiblock_parallel": "%s :buıssǝɔoɹԀ ıʇןnW",
"behavior.portable_scanner.player_name": "ɹ§%s :ǝuıןuO ɹǝʎɐןԀㄥ§ 'ɹ§%s :ǝɯɐN ɹǝʎɐןԀᄅ§",
"behavior.portable_scanner.position": "----- %s :ᗡ %s :Z %s :ʎ %s :X -----",
"behavior.portable_scanner.state": "%s :%s",
"behavior.portable_scanner.tank": "%s ᗺɯ %s / ᗺɯ %s :%s ʞuɐ⟘",
"behavior.portable_scanner.tanks_empty": "ʎʇdɯƎ sʞuɐ⟘ ןןⱯ",
"behavior.portable_scanner.team_name": "ɹ§%s :ǝɯɐN ɯɐǝ⟘ᄅ§",
"behavior.portable_scanner.workable_consumption": "Ɐ %s ʇɐ ʇ/∩Ǝ %s :sǝs∩ ʎןqɐqoɹԀ",
"behavior.portable_scanner.workable_production": "Ɐ %s ʇɐ ʇ/∩Ǝ %s :sǝɔnpoɹԀ ʎןqɐqoɹԀ",
"behavior.portable_scanner.workable_progress": "s %s / s %s :ssǝɹboɹԀ",
Expand Down Expand Up @@ -2287,6 +2291,8 @@
"config.gtceu.option.ldFluidPipeMinDistance": "ǝɔuɐʇsıᗡuıWǝdıԀpınןℲpן",
"config.gtceu.option.ldItemPipeMinDistance": "ǝɔuɐʇsıᗡuıWǝdıԀɯǝʇIpן",
"config.gtceu.option.liquidBoilerBaseOutput": "ʇndʇnOǝsɐᗺɹǝןıoᗺpınbıן",
"config.gtceu.option.machineOwnerBreak": "ʞɐǝɹᗺɹǝuʍOǝuıɥɔɐɯ",
"config.gtceu.option.machineOwnerGUI": "I∩⅁ɹǝuʍOǝuıɥɔɐɯ",
"config.gtceu.option.machineSounds": "spunoSǝuıɥɔɐɯ",
"config.gtceu.option.machines": "sǝuıɥɔɐɯ",
"config.gtceu.option.machinesEmissiveTextures": "sǝɹnʇxǝ⟘ǝʌıssıɯƎsǝuıɥɔɐɯ",
Expand Down
6 changes: 6 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"behavior.portable_scanner.environmental_hazard": "Environmental Hazard In Chunk: %s§r - %s ppm",
"behavior.portable_scanner.environmental_hazard.nothing": "Environmental Hazard In Chunk: §6Nothing§r",
"behavior.portable_scanner.eu_per_sec": "Average (last second): %s EU/t",
"behavior.portable_scanner.guild_name": "§2Guild Name: %s§r",
"behavior.portable_scanner.local_hazard": "Local Hazard In Area: %s§r - %s ppm",
"behavior.portable_scanner.local_hazard.nothing": "Local Hazard In Area: §6Nothing§r",
"behavior.portable_scanner.machine_disabled": "Disabled.",
"behavior.portable_scanner.machine_front_facing": "Front Facing: %s",
"behavior.portable_scanner.machine_ownership": "§2Machine Owner Type: %s§r",
"behavior.portable_scanner.machine_power_loss": "Shut down due to power loss.",
"behavior.portable_scanner.machine_progress": "Progress/Load: %s / %s",
"behavior.portable_scanner.machine_upwards_facing": "Upwards Facing: %s",
Expand All @@ -42,10 +44,12 @@
"behavior.portable_scanner.multiblock_energy_output": "Max Energy Output: %s EU/t Tier: %s",
"behavior.portable_scanner.multiblock_maintenance": "Problems: %s",
"behavior.portable_scanner.multiblock_parallel": "Multi Processing: %s",
"behavior.portable_scanner.player_name": "§2Player Name: %s§r, §7Player Online: %s§r",
"behavior.portable_scanner.position": "----- X: %s Y: %s Z: %s D: %s -----",
"behavior.portable_scanner.state": "%s: %s",
"behavior.portable_scanner.tank": "Tank %s: %s mB / %s mB %s",
"behavior.portable_scanner.tanks_empty": "All Tanks Empty",
"behavior.portable_scanner.team_name": "§2Team Name: %s§r",
"behavior.portable_scanner.workable_consumption": "Probably Uses: %s EU/t at %s A",
"behavior.portable_scanner.workable_production": "Probably Produces: %s EU/t at %s A",
"behavior.portable_scanner.workable_progress": "Progress: %s s / %s s",
Expand Down Expand Up @@ -2287,6 +2291,8 @@
"config.gtceu.option.ldFluidPipeMinDistance": "ldFluidPipeMinDistance",
"config.gtceu.option.ldItemPipeMinDistance": "ldItemPipeMinDistance",
"config.gtceu.option.liquidBoilerBaseOutput": "liquidBoilerBaseOutput",
"config.gtceu.option.machineOwnerBreak": "machineOwnerBreak",
"config.gtceu.option.machineOwnerGUI": "machineOwnerGUI",
"config.gtceu.option.machineSounds": "machineSounds",
"config.gtceu.option.machines": "machines",
"config.gtceu.option.machinesEmissiveTextures": "machinesEmissiveTextures",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"gtceu:rubber_wood",
"gtceu:stripped_rubber_wood"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"values": [
"gtceu:rubber_log"
"gtceu:rubber_log",
"gtceu:stripped_rubber_log",
"gtceu:rubber_wood",
"gtceu:stripped_rubber_wood"
]
}
8 changes: 8 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/GTCEu.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public static boolean isJAVDLoaded() {
return LDLib.isModLoaded(GTValues.MODID_JAVD);
}

public static boolean isFTBTeamsLoaded() {
return LDLib.isModLoaded(GTValues.MODID_FTBTEAMS);
}

public static boolean isArgonautsLoaded() {
return LDLib.isModLoaded(GTValues.MODID_ARGONAUTS);
}

@Deprecated(forRemoval = true, since = "1.0.21")
public static boolean isHighTier() {
return GTCEuAPI.isHighTier();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/gregtechceu/gtceu/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public static int[] tiersBetween(int minInclusive, int maxInclusive) {
MODID_CURIOS = "curios",
MODID_AE2WTLIB = "ae2wtlib",
MODID_SHIMMER = "shimmer",
MODID_JAVD = "javd";
MODID_JAVD = "javd",
MODID_FTBTEAMS = "ftbteams",
MODID_ARGONAUTS = "argonauts";

/**
* Spray painting compat modids
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.block;

import com.gregtechceu.gtceu.api.blockentity.MetaMachineBlockEntity;
import com.gregtechceu.gtceu.api.data.RotationState;
import com.gregtechceu.gtceu.api.item.IGTTool;
import com.gregtechceu.gtceu.api.item.MetaMachineItem;
Expand All @@ -11,6 +12,11 @@
import com.gregtechceu.gtceu.api.machine.MultiblockMachineDefinition;
import com.gregtechceu.gtceu.api.machine.feature.*;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.common.machine.owner.ArgonautsOwner;
import com.gregtechceu.gtceu.common.machine.owner.FTBOwner;
import com.gregtechceu.gtceu.common.machine.owner.GTOwner;
import com.gregtechceu.gtceu.common.machine.owner.IMachineOwner;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.utils.GTUtil;

import com.lowdragmc.lowdraglib.client.renderer.IRenderer;
Expand Down Expand Up @@ -46,10 +52,15 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

import dev.ftb.mods.ftbteams.FTBTeamsAPIImpl;
import dev.ftb.mods.ftbteams.api.Team;
import earth.terrarium.argonauts.api.guild.Guild;
import earth.terrarium.argonauts.common.handlers.guild.GuildHandler;
import lombok.Getter;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -127,6 +138,12 @@ public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, @Nullabl
ItemStack pStack) {
if (!pLevel.isClientSide) {
var machine = getMachine(pLevel, pPos);
if (machine != null) {
if (player instanceof ServerPlayer sPlayer) {
setMachineOwner(machine, sPlayer);
machine.markDirty();
}
}
if (machine instanceof IDropSaveMachine dropSaveMachine) {
CompoundTag tag = pStack.getTag();
if (tag != null) {
Expand All @@ -139,6 +156,24 @@ public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, @Nullabl
}
}

public final void setMachineOwner(MetaMachine machine, ServerPlayer player) {
YoungOnionMC marked this conversation as resolved.
Show resolved Hide resolved
if (IMachineOwner.MachineOwnerType.FTB.isAvailable()) {
Optional<Team> team = FTBTeamsAPIImpl.INSTANCE.getManager().getTeamForPlayerID(player.getUUID());
if (team.isPresent()) {
machine.holder.setOwner(new FTBOwner(team.get(), player.getUUID()));
return;
}
}
if (IMachineOwner.MachineOwnerType.ARGONAUTS.isAvailable()) {
Guild guild = GuildHandler.read(player.server).get(player);
if (guild != null) {
machine.holder.setOwner(new ArgonautsOwner(guild, player.getUUID()));
return;
}
}
machine.holder.setOwner(new GTOwner(player.getUUID()));
}

@Override
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
super.onPlace(state, level, pos, oldState, movedByPiston);
Expand Down Expand Up @@ -282,6 +317,11 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
ItemStack itemStack = player.getItemInHand(hand);
boolean shouldOpenUi = true;

if (machine != null && machine.holder.getOwner() == null && player instanceof ServerPlayer) {
setMachineOwner(machine, (ServerPlayer) player);
machine.markDirty();
}

Set<GTToolType> types = ToolHelper.getToolTypes(itemStack);
if (machine != null && !types.isEmpty() && ToolHelper.canUse(itemStack)) {
var result = machine.onToolClick(types, itemStack, new UseOnContext(player, hand, hit));
Expand All @@ -307,12 +347,31 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
var result = interactedMachine.onUse(state, world, pos, player, hand, hit);
if (result != InteractionResult.PASS) return result;
}
if (shouldOpenUi && machine instanceof IUIMachine uiMachine) {
if (shouldOpenUi && machine instanceof IUIMachine uiMachine &&
canOpenOwnerMachine(player, machine.getHolder())) {
return uiMachine.tryToOpenUI(player, hand, hit);
}
return shouldOpenUi ? InteractionResult.PASS : InteractionResult.CONSUME;
}

public boolean canOpenOwnerMachine(Player player, IMachineBlockEntity machineBlockEntity) {
if (!ConfigHolder.INSTANCE.machines.machineOwnerGUI) return true;
if (machineBlockEntity instanceof MetaMachineBlockEntity mmBE) {
YoungOnionMC marked this conversation as resolved.
Show resolved Hide resolved
if (mmBE.getOwner() == null) return true;
return mmBE.getOwner().isPlayerInTeam(player) || mmBE.getOwner().isPlayerFriendly(player);
}
return false;
}

public static boolean canBreakOwnerMachine(Player player, IMachineBlockEntity machineBlockEntity) {
if (!ConfigHolder.INSTANCE.machines.machineOwnerBreak) return true;
if (machineBlockEntity instanceof MetaMachineBlockEntity mmBE) {
YoungOnionMC marked this conversation as resolved.
Show resolved Hide resolved
if (mmBE.getOwner() == null) return true;
return mmBE.getOwner().isPlayerInTeam(player);
}
return false;
}

public boolean canConnectRedstone(BlockGetter level, BlockPos pos, Direction side) {
return getMachine(level, pos).canConnectRedstone(side);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.gregtechceu.gtceu.api.misc.LaserContainerList;
import com.gregtechceu.gtceu.api.pipenet.longdistance.ILDEndpoint;
import com.gregtechceu.gtceu.client.renderer.GTRendererProvider;
import com.gregtechceu.gtceu.common.machine.owner.IMachineOwner;
import com.gregtechceu.gtceu.common.pipelike.fluidpipe.longdistance.LDFluidEndpointMachine;
import com.gregtechceu.gtceu.common.pipelike.item.longdistance.LDItemEndpointMachine;

Expand All @@ -25,10 +26,12 @@
import com.lowdragmc.lowdraglib.side.fluid.forge.FluidTransferHelperImpl;
import com.lowdragmc.lowdraglib.side.item.IItemTransfer;
import com.lowdragmc.lowdraglib.side.item.forge.ItemTransferHelperImpl;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.managed.MultiManagedStorage;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -45,13 +48,11 @@
import appeng.api.networking.IInWorldGridNodeHost;
import appeng.capabilities.Capabilities;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;

/**
* @author KilaBash
Expand All @@ -63,6 +64,9 @@ public class MetaMachineBlockEntity extends BlockEntity implements IMachineBlock
public final MultiManagedStorage managedStorage = new MultiManagedStorage();
@Getter
public final MetaMachine metaMachine;
@Setter
@Persisted
private IMachineOwner owner;
private final long offset = GTValues.RNG.nextInt(20);

protected MetaMachineBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
Expand All @@ -82,6 +86,11 @@ public MultiManagedStorage getRootStorage() {
return managedStorage;
}

@Override
public IMachineOwner getOwner() {
return owner;
}
YoungOnionMC marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean triggerEvent(int id, int para) {
if (id == 1) { // chunk re render
Expand Down Expand Up @@ -317,4 +326,20 @@ public AABB getRenderBoundingBox() {
}
return new AABB(worldPosition.offset(-1, 0, -1), worldPosition.offset(2, 2, 2));
}

@Override
protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
YoungOnionMC marked this conversation as resolved.
Show resolved Hide resolved
if (owner != null) {
tag.put("owner", IMachineOwner.write(owner));
YoungOnionMC marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public void load(CompoundTag tag) {
super.load(tag);
if (tag.contains("owner")) {
this.owner = IMachineOwner.create(tag.getCompound("owner"));
}
}
}
Loading