Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import io.wispforest.affinity.blockentity.template.TickedBlockEntity;
import io.wispforest.affinity.object.AffinityBlocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
Expand All @@ -33,6 +31,7 @@
public class SunshineMonolithBlock extends AethumNetworkMemberBlock {

public static final BooleanProperty ENABLED = Properties.ENABLED;
public static final BooleanProperty POWERED = Properties.POWERED;
public static final EnumProperty<DoubleBlockHalf> HALF = Properties.DOUBLE_BLOCK_HALF;

public static final VoxelShape LOWER_SHAPE = VoxelShapes.union(
Expand All @@ -43,8 +42,25 @@ public class SunshineMonolithBlock extends AethumNetworkMemberBlock {
public static final VoxelShape UPPER_SHAPE = Block.createCuboidShape(2, 0, 2, 14, 16, 14);

public SunshineMonolithBlock() {
super(FabricBlockSettings.copyOf(Blocks.SMOOTH_STONE), CONSUMER_TOOLTIP);
this.setDefaultState(this.getDefaultState().with(Properties.ENABLED, false).with(HALF, DoubleBlockHalf.LOWER));
super(Settings.copy(Blocks.SMOOTH_STONE), CONSUMER_TOOLTIP);
this.setDefaultState(this.getDefaultState().with(ENABLED, false).with(HALF, DoubleBlockHalf.LOWER).with(POWERED, false));
}

@Override
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
var otherHalfPos = pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN);
var powered = world.isReceivingRedstonePower(pos) | world.isReceivingRedstonePower(otherHalfPos);

if (state.get(POWERED) != powered) {
world.setBlockState(pos, state.with(POWERED, powered), 2);

var otherState = world.getBlockState(otherHalfPos);
if (otherState.isOf(this) && otherState.get(POWERED) != powered) {
world.setBlockState(otherHalfPos, otherState.with(POWERED, powered));
}
}

super.neighborUpdate(state, world, pos, sourceBlock, sourcePos, notify);
}

@Override
Expand Down Expand Up @@ -75,9 +91,10 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio
public BlockState getPlacementState(ItemPlacementContext context) {
var pos = context.getBlockPos();
var world = context.getWorld();
var powered = world.isReceivingRedstonePower(pos);

return pos.getY() < world.getTopY() - 1 && world.getBlockState(pos.up()).canReplace(context)
? super.getPlacementState(context)
? super.getPlacementState(context).with(POWERED, powered)
: null;
}

Expand All @@ -94,14 +111,25 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return downState.isOf(this) && downState.get(HALF) == DoubleBlockHalf.LOWER;
}

@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
// This is how vanilla doors handle preventing unwanted drops
if (!world.isClient && (player.isCreative() || !player.canHarvest(state))) {
TallPlantBlock.onBreakInCreative(world, pos, state, player);
}

return super.onBreak(world, pos, state, player);
}


@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return state.get(HALF) == DoubleBlockHalf.LOWER ? LOWER_SHAPE : UPPER_SHAPE;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.ENABLED).add(HALF);
builder.add(ENABLED).add(HALF).add(POWERED);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package io.wispforest.affinity.blockentity.impl;

import io.wispforest.affinity.aethumflux.net.AethumNetworkMember;
import io.wispforest.affinity.aethumflux.net.MultiblockAethumNetworkMember;
import io.wispforest.affinity.block.impl.SunshineMonolithBlock;
import io.wispforest.affinity.blockentity.template.AethumNetworkMemberBlockEntity;
import io.wispforest.affinity.blockentity.template.TickedBlockEntity;
import io.wispforest.affinity.component.AffinityComponents;
import io.wispforest.affinity.object.AffinityBlocks;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;

public class SunshineMonolithBlockEntity extends AethumNetworkMemberBlockEntity implements TickedBlockEntity {
import java.util.Collection;
import java.util.List;

public class SunshineMonolithBlockEntity extends AethumNetworkMemberBlockEntity implements TickedBlockEntity, MultiblockAethumNetworkMember {
public SunshineMonolithBlockEntity(BlockPos pos, BlockState state) {
super(AffinityBlocks.Entities.SUNSHINE_MONOLITH, pos, state);

Expand All @@ -19,7 +26,7 @@ public SunshineMonolithBlockEntity(BlockPos pos, BlockState state) {
@Override
public void tickServer() {
long flux = flux();
boolean shouldBeEnabled = flux >= 1;
boolean shouldBeEnabled = flux >= 1 && !this.getCachedState().get(SunshineMonolithBlock.POWERED);

if (shouldBeEnabled != this.getCachedState().get(SunshineMonolithBlock.ENABLED)) {
this.world.setBlockState(this.pos, this.getCachedState().with(SunshineMonolithBlock.ENABLED, shouldBeEnabled));
Expand Down Expand Up @@ -66,4 +73,28 @@ private void removeMonolithFromChunks() {
}
}
}

@Override
public void appendTooltipEntries(List<Entry> entries) {
super.appendTooltipEntries(entries);

if (getCachedState().get(Properties.POWERED)) {
entries.add(Entry.icon(Text.translatable("text.affinity.tooltip.disabled_by_redstone"), 24, 8));
}
}

@Override
public Collection<BlockPos> memberBlocks() {
return List.of(this.getPos(), this.getPos().up());
}

@Override
public boolean isParent() {
return true;
}

@Override
public AethumNetworkMember parent() {
return this;
}
}
15 changes: 15 additions & 0 deletions src/main/java/io/wispforest/affinity/mixin/ServerWorldMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.wispforest.affinity.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import io.wispforest.affinity.Affinity;
import io.wispforest.affinity.component.AffinityComponents;
Expand Down Expand Up @@ -93,4 +95,17 @@ private BlockPos makeSunshineMonolithsStopThunder(BlockPos pos) {

return pos;
}

// tickIceAndSnow doesn't use the position-aware hasRain call hooked in WorldMixin
// Ice is still permitted to form, only precipitation is blocked
@WrapOperation(method = "tickIceAndSnow", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;isRaining()Z"))
private boolean makeSunshineMonolithPreventSnow(ServerWorld instance, Operation<Boolean> original, BlockPos pos) {
var chunk = getWorldChunk(pos);
if (chunk instanceof EmptyChunk) {
return original.call(instance);
}

var component = chunk.getComponent(AffinityComponents.LOCAL_WEATHER);
return component.getRainGradient() > 0.2;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/affinity.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ accessible field net/minecraft/block/CandleBlock CANDLES_TO_PARTICLE_OFFSETS Lit

accessible class net/minecraft/server/world/ServerChunkLoadingManager$TicketManager

accessible class net/minecraft/datafixer/fix/ItemStackComponentizationFix$StackData
accessible class net/minecraft/datafixer/fix/ItemStackComponentizationFix$StackData

accessible method net/minecraft/block/TallPlantBlock onBreakInCreative (Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V
1 change: 1 addition & 0 deletions src/main/resources/assets/affinity/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@

"text.affinity.tooltip.aethum_storage": "Flux: %d/%d",
"text.affinity.tooltip.creative_flux_cache_flux_level": "All of it, really",
"text.affinity.tooltip.disabled_by_redstone": "Disabled by redstone",

"death.attack.asteroid": "%s was expunged by an Asteroid",
"death.attack.asteroid.player": "%s was expunged by %s's Asteroid",
Expand Down
Binary file modified src/main/resources/assets/affinity/textures/gui/tooltip_icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.