Skip to content

Commit

Permalink
Test commit: Satellite name will store in module instead of pipe, all…
Browse files Browse the repository at this point in the history
…ow it to be stored properly on early loading stage.
  • Loading branch information
KorewaLidesu committed Mar 10, 2023
1 parent 4d3c4e3 commit bdd1aba
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 33 deletions.
21 changes: 19 additions & 2 deletions common/logisticspipes/modules/ModuleSatellite.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package logisticspipes.modules;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.NotNull;

import logisticspipes.interfaces.IPipeServiceProvider;
import logisticspipes.proxy.MainProxy;
import logisticspipes.utils.SinkReply;
import logisticspipes.utils.SinkReply.FixedPriority;
import logisticspipes.utils.item.ItemIdentifier;
import network.rs485.logisticspipes.connection.LPNeighborTileEntityKt;
import network.rs485.logisticspipes.SatellitePipe;
import network.rs485.logisticspipes.property.StringProperty;
import network.rs485.logisticspipes.property.Property;

public class ModuleSatellite extends LogisticsModule {

private final SinkReply _sinkReply = new SinkReply(FixedPriority.ItemSink, 0, true, false, 1, 0, null);

public final StringProperty satellitePipeName = new StringProperty("", "satellitePipeName", "satelliteid");
private final List<Property<?>> properties = ImmutableList.<Property<?>>builder()
.add(satellitePipeName)
.build();

@Nonnull
@Override
public String getLPName() {
Expand All @@ -29,7 +38,7 @@ public String getLPName() {
@NotNull
@Override
public List<Property<?>> getProperties() {
return Collections.emptyList();
return properties;
}

@Override
Expand Down Expand Up @@ -85,4 +94,12 @@ public boolean receivePassive() {
return false;
}

@Override
public void readFromNBT(@NotNull NBTTagCompound tag) {
super.readFromNBT(tag);
if (MainProxy.isServer(getWorld()) && _service != null) {
((SatellitePipe) _service).ensureAllSatelliteStatus();
}
}

}
47 changes: 16 additions & 31 deletions common/logisticspipes/pipes/PipeItemsSatelliteLogistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import logisticspipes.LogisticsPipes;
import logisticspipes.gui.hud.HUDSatellite;
Expand Down Expand Up @@ -69,9 +68,6 @@ public static void cleanup() {
protected final LinkedList<ItemIdentifierStack> _lostItems = new LinkedList<>();
private final ModuleSatellite moduleSatellite;

@Getter
private String satellitePipeName = "";

public PipeItemsSatelliteLogistics(Item item) {
super(item);
throttleTime = 40;
Expand Down Expand Up @@ -142,7 +138,8 @@ private void updateInv(boolean force) {
public void playerStartWatching(EntityPlayer player, int mode) {
if (mode == 1) {
localModeWatchers.add(player);
final ModernPacket packet = PacketHandler.getPacket(SyncSatelliteNamePacket.class).setString(satellitePipeName).setPosX(getX()).setPosY(getY()).setPosZ(getZ());
final ModernPacket packet = PacketHandler.getPacket(SyncSatelliteNamePacket.class).setString(this.moduleSatellite.satellitePipeName.getValue())
.setPosX(getX()).setPosY(getY()).setPosZ(getZ());
MainProxy.sendPacketToPlayer(packet, player);
updateInv(true);
} else {
Expand All @@ -167,37 +164,18 @@ public IHeadUpDisplayRenderer getRenderer() {
return HUD;
}

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("satelliteid")) {
int satelliteId = nbttagcompound.getInteger("satelliteid");
satellitePipeName = Integer.toString(satelliteId);
} else {
satellitePipeName = nbttagcompound.getString("satellitePipeName");
}
if (MainProxy.isServer(getWorld())) {
ensureAllSatelliteStatus();
}
}

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setString("satellitePipeName", satellitePipeName);
super.writeToNBT(nbttagcompound);
}

public void ensureAllSatelliteStatus() {
if (satellitePipeName.isEmpty()) {
if (this.moduleSatellite.satellitePipeName.isEmpty()) {
PipeItemsSatelliteLogistics.AllSatellites.remove(this);
}
if (!satellitePipeName.isEmpty()) {
if (!this.moduleSatellite.satellitePipeName.isEmpty()) {
PipeItemsSatelliteLogistics.AllSatellites.add(this);
}
}

public void updateWatchers() {
CoordinatesPacket packet = PacketHandler.getPacket(SyncSatelliteNamePacket.class).setString(satellitePipeName).setTilePos(this.getContainer());
CoordinatesPacket packet = PacketHandler.getPacket(SyncSatelliteNamePacket.class).setString(this.moduleSatellite.satellitePipeName.getValue())
.setTilePos(this.getContainer());
MainProxy.sendToPlayerList(packet, localModeWatchers);
MainProxy.sendPacketToAllWatchingChunk(this.getContainer(), packet);
}
Expand All @@ -213,7 +191,8 @@ public void onAllowedRemoval() {
@Override
public void onWrenchClicked(EntityPlayer entityplayer) {
// Send the satellite id when opening gui
final ModernPacket packet = PacketHandler.getPacket(SyncSatelliteNamePacket.class).setString(satellitePipeName).setPosX(getX()).setPosY(getY()).setPosZ(getZ());
final ModernPacket packet = PacketHandler.getPacket(SyncSatelliteNamePacket.class).setString(this.moduleSatellite.satellitePipeName.getValue())
.setPosX(getX()).setPosY(getY()).setPosZ(getZ());
MainProxy.sendPacketToPlayer(packet, entityplayer);
entityplayer.openGui(LogisticsPipes.instance, GuiIDs.GUI_SatellitePipe_ID, getWorld(), getX(), getY(), getZ());
}
Expand Down Expand Up @@ -255,12 +234,18 @@ public Set<SatellitePipe> getSatellitesOfType() {

@Override
public void setSatellitePipeName(@Nonnull String satellitePipeName) {
this.satellitePipeName = satellitePipeName;
this.moduleSatellite.satellitePipeName.setValue(satellitePipeName);
}

@Nonnull
@Override
public List<ItemIdentifierStack> getItemList() {
return itemList;
}

@NotNull
@Override
public String getSatellitePipeName() {
return this.moduleSatellite.satellitePipeName.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import java.util.concurrent.CopyOnWriteArraySet

interface Property<V> : IStore {
val tagKey: String
val oldTagKey: String
get() = ""
val propertyObservers: CopyOnWriteArraySet<ObserverCallback<V>>

fun iChanged() = propertyObservers.forEach { observer -> observer.invoke(this) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 RS485
*
* "LogisticsPipes" is distributed under the terms of the Minecraft Mod Public
* License 1.0.1, or MMPL. Please check the contents of the license located in
* https://github.com/RS485/LogisticsPipes/blob/dev/LICENSE.md
*
* This file can instead be distributed under the license terms of the
* MIT license:
*
* Copyright (c) 2023 RS485
*
* This MIT license was reworded to only match this file. If you use the regular
* MIT license in your project, replace this copyright notice (this line and any
* lines below and NOT the copyright line above) with the lines from the original
* MIT license located here: http://opensource.org/licenses/MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this file and associated documentation files (the "Source Code"), to deal in
* the Source Code without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Source Code, and to permit persons to whom the Source Code is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Source Code, which also can be
* distributed under the MIT.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package network.rs485.logisticspipes.property

import net.minecraft.nbt.NBTTagCompound

class StringProperty(initialValue: String, override val tagKey: String, override val oldTagKey: String) : ValueProperty<String>(initialValue) {

constructor(initialValue: String, tagKey: String) : this(initialValue, tagKey, "")

override fun readFromNBT(tag: NBTTagCompound) {
if (!oldTagKey.isEmpty() && tag.hasKey(oldTagKey)) value = tag.getString(oldTagKey)
else if (tag.hasKey(tagKey)) value = tag.getString(tagKey)
}

override fun writeToNBT(tag: NBTTagCompound) = tag.setString(tagKey, value)

override fun copyValue(): String = value

override fun copyProperty(): StringProperty = StringProperty(copyValue(), tagKey)

fun isEmpty(): Boolean = value.isEmpty()

}

0 comments on commit bdd1aba

Please sign in to comment.