Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.21' into 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Dec 12, 2024
2 parents 9216294 + 3c66e61 commit 8eac6c5
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.accelerator.AcceleratorSensorBlockEntity;
import rearth.oritech.util.ComparatorOutputProvider;

import java.util.List;

Expand All @@ -31,7 +32,7 @@ protected boolean hasComparatorOutput(BlockState state) {

@Override
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ((AcceleratorSensorBlockEntity) world.getBlockEntity(pos)).getComparatorOutput();
return ((ComparatorOutputProvider) world.getBlockEntity(pos)).getComparatorOutput();
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.addons.RedstoneAddonBlockEntity;
import rearth.oritech.util.ComparatorOutputProvider;

public class RedstoneAddonBlock extends MachineAddonBlock {

Expand All @@ -44,7 +45,7 @@ protected boolean hasComparatorOutput(BlockState state) {

@Override
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ((RedstoneAddonBlockEntity) world.getBlockEntity(pos)).currentOutput;
return ((ComparatorOutputProvider) world.getBlockEntity(pos)).getComparatorOutput();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.arcane.EnchantmentCatalystBlockEntity;
import rearth.oritech.util.ComparatorOutputProvider;

import java.util.List;
import java.util.Objects;
Expand All @@ -41,7 +42,7 @@ protected boolean hasComparatorOutput(BlockState state) {

@Override
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ((EnchantmentCatalystBlockEntity) world.getBlockEntity(pos)).getComparatorOutput();
return ((ComparatorOutputProvider) world.getBlockEntity(pos)).getComparatorOutput();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package rearth.oritech.block.blocks.pipes;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.SoundCategory;
Expand All @@ -27,6 +24,7 @@
import rearth.oritech.item.tools.Wrench;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public abstract class GenericPipeBlock extends Block implements Wrench.Wrenchable {
Expand Down Expand Up @@ -147,9 +145,15 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio

// transform to interface when machine is placed as neighbor
if (hasMachineInDirection(direction, world, pos, apiValidationFunction())) {
// Only update if the neighbor is a new machine
var hasMachine = getNetworkData(world).machinePipeNeighbors.getOrDefault(neighborPos, HashSet.newHashSet(0)).contains(direction.getOpposite());
if (hasMachine) return state;

var connectionBlock = getConnectionBlock();
return ((GenericPipeBlock) connectionBlock.getBlock()).addConnectionStates(connectionBlock, world, pos, direction);
}
} else if (neighborState.isOf(Blocks.AIR))
// remove potential stale machine -> neighboring pipes mapping
getNetworkData(world).machinePipeNeighbors.remove(neighborPos);

return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
Expand All @@ -17,6 +18,8 @@
import rearth.oritech.Oritech;
import rearth.oritech.block.entity.pipes.GenericPipeInterfaceEntity;

import java.util.HashSet;

public abstract class GenericPipeConnectionBlock extends GenericPipeBlock implements BlockEntityProvider {

public GenericPipeConnectionBlock(Settings settings) {
Expand Down Expand Up @@ -46,13 +49,20 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio
if (worldImp.isClient) return state;

if (!hasNeighboringMachine(state, worldImp, pos, false)) {
// remove stale machine -> neighboring pipes mapping
GenericPipeInterfaceEntity.removeStaleMachinePipeNeighbors(pos, getNetworkData(worldImp));

var normalState = getNormalBlock();
return ((GenericPipeBlock) normalState.getBlock()).addConnectionStates(normalState, worldImp, pos, false);
}

var interfaceState = state;
if (!(neighborState.getBlock() instanceof GenericPipeBlock)) {
interfaceState = addConnectionStates(state, worldImp, pos, direction);
// only update connection if neighbor is a new machine
var hadMachine = getNetworkData(worldImp).machinePipeNeighbors.getOrDefault(neighborPos, HashSet.newHashSet(0)).contains(direction.getOpposite());
if (state.isOf(Blocks.AIR) || !hadMachine) {
interfaceState = addConnectionStates(state, worldImp, pos, direction);
}

if (!interfaceState.equals(state)) {
// reload connection when state has changed (e.g. machine added/removed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.storage.SmallFluidTankEntity;
import rearth.oritech.init.BlockContent;
import rearth.oritech.util.ComparatorOutputProvider;

import java.util.List;

Expand Down Expand Up @@ -64,7 +65,7 @@ protected boolean hasComparatorOutput(BlockState state) {

@Override
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ((SmallFluidTankEntity) world.getBlockEntity(pos)).getComparatorOutput();
return ((ComparatorOutputProvider) world.getBlockEntity(pos)).getComparatorOutput();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import rearth.oritech.block.base.entity.ExpandableEnergyStorageBlockEntity;
import rearth.oritech.block.entity.storage.SmallStorageBlockEntity;
import rearth.oritech.init.BlockContent;
import rearth.oritech.util.ComparatorOutputProvider;
import rearth.oritech.util.MachineAddonController;

import java.util.List;
Expand Down Expand Up @@ -79,7 +80,7 @@ protected boolean hasComparatorOutput(BlockState state) {

@Override
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ((SmallStorageBlockEntity) world.getBlockEntity(pos)).getComparatorOutput();
return ((ComparatorOutputProvider) world.getBlockEntity(pos)).getComparatorOutput();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import rearth.oritech.init.BlockEntitiesContent;
import rearth.oritech.util.ComparatorOutputProvider;

public class AcceleratorSensorBlockEntity extends BlockEntity implements BlockEntityTicker<AcceleratorSensorBlockEntity> {
public class AcceleratorSensorBlockEntity extends BlockEntity implements BlockEntityTicker<AcceleratorSensorBlockEntity>, ComparatorOutputProvider {

private float measuredSpeed;
private long measuredTime;
Expand Down Expand Up @@ -42,7 +43,8 @@ public void measureParticle(AcceleratorParticleLogic.ActiveParticle particle) {
this.measuredTime = world.getTime();
dirty = true;
}


@Override
public int getComparatorOutput() {
if (measuredSpeed <= 0) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import rearth.oritech.client.ui.RedstoneAddonScreenHandler;
import rearth.oritech.init.BlockEntitiesContent;
import rearth.oritech.network.NetworkContent;
import rearth.oritech.util.ComparatorOutputProvider;

public class RedstoneAddonBlockEntity extends AddonBlockEntity implements BlockEntityTicker<RedstoneAddonBlockEntity>, ExtendedScreenHandlerFactory {
public class RedstoneAddonBlockEntity extends AddonBlockEntity implements BlockEntityTicker<RedstoneAddonBlockEntity>, ExtendedScreenHandlerFactory, ComparatorOutputProvider {

private RedstoneControllable cachedController;
public RedstoneMode activeMode = RedstoneMode.INPUT_CONTROL;
Expand Down Expand Up @@ -99,7 +100,12 @@ public void setRedstonePowered(boolean isPowered) {
cachedController.onRedstoneEvent(isPowered);

}


@Override
public int getComparatorOutput() {
return currentOutput;
}

@Override
public Object getScreenOpeningData(ServerPlayerEntity player) {
sendDataToClient();
Expand Down Expand Up @@ -133,12 +139,21 @@ public enum RedstoneMode {
OUTPUT_POWER, OUTPUT_SLOT, OUTPUT_PROGRESS, OUTPUT_ACTIVE, INPUT_CONTROL
}

public interface RedstoneControllable {
public interface RedstoneControllable extends ComparatorOutputProvider {
int getComparatorEnergyAmount();
int getComparatorSlotAmount(int slot);
int getComparatorProgress();
int getComparatorActiveState();
void onRedstoneEvent(boolean isPowered);

/**
* A redstone controllable machine only outputs a readable comparator signal from the controller addon block.
* @return 0
*/
@Override
default int getComparatorOutput() {
return 0;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.List;

public class EnchantmentCatalystBlockEntity extends BaseSoulCollectionEntity
implements InventoryProvider, EnergyApi.BlockProvider, ScreenProvider, GeoBlockEntity, BlockEntityTicker<EnchantmentCatalystBlockEntity>, ExtendedScreenHandlerFactory<ModScreens.BasicData> {
implements InventoryProvider, EnergyApi.BlockProvider, ScreenProvider, ComparatorOutputProvider, GeoBlockEntity, BlockEntityTicker<EnchantmentCatalystBlockEntity>, ExtendedScreenHandlerFactory<ModScreens.BasicData> {

public static final RawAnimation IDLE = RawAnimation.begin().thenLoop("idle");
public static final RawAnimation STABILIZED = RawAnimation.begin().thenLoop("stabilized");
Expand Down Expand Up @@ -275,7 +275,8 @@ public void onSoulIncoming(Vec3d source) {
public boolean canAcceptSoul() {
return collectedSouls < maxSouls;
}


@Override
public int getComparatorOutput() {
return calculateComparatorLevel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import rearth.oritech.init.BlockEntitiesContent;
import rearth.oritech.init.TagContent;
import rearth.oritech.network.NetworkContent;
import rearth.oritech.util.ComparatorOutputProvider;

public class SpawnerControllerBlockEntity extends BaseSoulCollectionEntity implements BlockEntityTicker<SpawnerControllerBlockEntity> {
public class SpawnerControllerBlockEntity extends BaseSoulCollectionEntity implements BlockEntityTicker<SpawnerControllerBlockEntity>, ComparatorOutputProvider {

public int maxSouls = 100_000;
public int collectedSouls = 0;
Expand Down Expand Up @@ -170,7 +171,8 @@ private void updateComparator() {
}

}


@Override
public int getComparatorOutput() {
if (spawnedMob == null || maxSouls == 0) return 0;

Expand Down
Loading

0 comments on commit 8eac6c5

Please sign in to comment.