-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: class hierarchy of network node containers
Introduced NetworkNodeContainerBlockEntityImpl, that inherits from the API block entity. It only has code for activeness checking. Modified AbstractInternalNetworkNodeContainerBlockEntity to have redstone mode, placed by and configuration card code. Modified cable and network receiver to inherit from NetworkNodeContainerBlockEntityImpl since they don't need redstone mode and especially not configuration card support.
- Loading branch information
1 parent
07e5445
commit 456a3cf
Showing
24 changed files
with
215 additions
and
212 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
36 changes: 36 additions & 0 deletions
36
...main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractColoredBlock.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,36 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.block; | ||
|
||
import com.refinedmods.refinedstorage2.platform.common.item.block.NamedBlockItem; | ||
|
||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.DyeColor; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.Block; | ||
|
||
public abstract class AbstractColoredBlock<T extends Block & BlockItemProvider> | ||
extends AbstractBaseBlock implements ColorableBlock<T>, BlockItemProvider { | ||
private final DyeColor color; | ||
private final MutableComponent name; | ||
|
||
protected AbstractColoredBlock(final Properties properties, final DyeColor color, final MutableComponent name) { | ||
super(properties); | ||
this.color = color; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public MutableComponent getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public DyeColor getColor() { | ||
return color; | ||
} | ||
|
||
@Override | ||
public BlockItem createBlockItem() { | ||
return new NamedBlockItem(this, new Item.Properties(), name); | ||
} | ||
} |
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
100 changes: 100 additions & 0 deletions
100
...ge2/platform/common/block/entity/AbstractRedstoneModeNetworkNodeContainerBlockEntity.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,100 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.block.entity; | ||
|
||
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; | ||
import com.refinedmods.refinedstorage2.platform.api.blockentity.ConfigurationCardTarget; | ||
import com.refinedmods.refinedstorage2.platform.common.Platform; | ||
import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public abstract class AbstractRedstoneModeNetworkNodeContainerBlockEntity<T extends AbstractNetworkNode> | ||
extends NetworkNodeContainerBlockEntityImpl<T> implements PlayerAware, ConfigurationCardTarget { | ||
private static final String TAG_REDSTONE_MODE = "rm"; | ||
private static final String TAG_PLACED_BY_PLAYER_ID = "pbpid"; | ||
|
||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE; | ||
@Nullable | ||
private UUID placedByPlayerId; | ||
|
||
protected AbstractRedstoneModeNetworkNodeContainerBlockEntity(final BlockEntityType<?> type, | ||
final BlockPos pos, | ||
final BlockState state, | ||
final T node) { | ||
super(type, pos, state, node); | ||
} | ||
|
||
@Override | ||
protected boolean isActive() { | ||
return super.isActive() && level != null && redstoneMode.isActive(level.hasNeighborSignal(worldPosition)); | ||
} | ||
|
||
@Override | ||
public void saveAdditional(final CompoundTag tag) { | ||
super.saveAdditional(tag); | ||
writeConfiguration(tag); | ||
if (placedByPlayerId != null) { | ||
tag.putUUID(TAG_PLACED_BY_PLAYER_ID, placedByPlayerId); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeConfiguration(final CompoundTag tag) { | ||
tag.putInt(TAG_REDSTONE_MODE, RedstoneModeSettings.getRedstoneMode(getRedstoneMode())); | ||
} | ||
|
||
@Override | ||
public void load(final CompoundTag tag) { | ||
super.load(tag); | ||
readConfiguration(tag); | ||
if (tag.hasUUID(TAG_PLACED_BY_PLAYER_ID)) { | ||
placedByPlayerId = tag.getUUID(TAG_PLACED_BY_PLAYER_ID); | ||
} | ||
} | ||
|
||
@Override | ||
public void readConfiguration(final CompoundTag tag) { | ||
if (tag.contains(TAG_REDSTONE_MODE)) { | ||
redstoneMode = RedstoneModeSettings.getRedstoneMode(tag.getInt(TAG_REDSTONE_MODE)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Item> getUpgradeItems() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public boolean addUpgradeItem(final Item upgradeItem) { | ||
return false; | ||
} | ||
|
||
public RedstoneMode getRedstoneMode() { | ||
return redstoneMode; | ||
} | ||
|
||
public void setRedstoneMode(final RedstoneMode redstoneMode) { | ||
this.redstoneMode = redstoneMode; | ||
setChanged(); | ||
} | ||
|
||
@Override | ||
public void setPlacedBy(final UUID playerId) { | ||
this.placedByPlayerId = playerId; | ||
setChanged(); | ||
} | ||
|
||
protected final Player getFakePlayer(final ServerLevel serverLevel) { | ||
return Platform.INSTANCE.getFakePlayer(serverLevel, placedByPlayerId); | ||
} | ||
} |
Oops, something went wrong.