-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement lithium block entity sleeping
- Loading branch information
Showing
6 changed files
with
110 additions
and
6 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
71 changes: 71 additions & 0 deletions
71
...va/com/github/tatercertified/fabricautocrafter/mixin/LithiumBlockEntityOptimizations.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,71 @@ | ||
package com.github.tatercertified.fabricautocrafter.mixin; | ||
|
||
import com.github.tatercertified.fabricautocrafter.AutoCraftingTableBlockEntity; | ||
import com.moulberry.mixinconstraints.annotations.IfModLoaded; | ||
import me.jellysquid.mods.lithium.common.block.entity.SleepingBlockEntity; | ||
import me.jellysquid.mods.lithium.mixin.world.block_entity_ticking.sleeping.WrappedBlockEntityTickInvokerAccessor; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.block.entity.LockableContainerBlockEntity; | ||
import net.minecraft.inventory.SidedInventory; | ||
import net.minecraft.recipe.RecipeInputProvider; | ||
import net.minecraft.recipe.RecipeUnlocker; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.chunk.BlockEntityTickInvoker; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
@IfModLoaded(value = "lithium") | ||
@Mixin(AutoCraftingTableBlockEntity.class) | ||
public abstract class LithiumBlockEntityOptimizations extends LockableContainerBlockEntity implements SidedInventory, RecipeUnlocker, RecipeInputProvider, SleepingBlockEntity { | ||
|
||
// Block Entity Sleeping | ||
private WrappedBlockEntityTickInvokerAccessor tickWrapper = null; | ||
private BlockEntityTickInvoker sleepingTicker = null; | ||
|
||
protected LithiumBlockEntityOptimizations(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { | ||
super(blockEntityType, blockPos, blockState); | ||
} | ||
|
||
@Override | ||
public WrappedBlockEntityTickInvokerAccessor lithium$getTickWrapper() { | ||
return this.tickWrapper; | ||
} | ||
|
||
@Override | ||
public void lithium$setTickWrapper(WrappedBlockEntityTickInvokerAccessor tickWrapper) { | ||
this.tickWrapper = tickWrapper; | ||
this.lithium$setSleepingTicker(null); | ||
} | ||
|
||
@Override | ||
public BlockEntityTickInvoker lithium$getSleepingTicker() { | ||
return this.sleepingTicker; | ||
} | ||
|
||
@Override | ||
public void lithium$setSleepingTicker(BlockEntityTickInvoker sleepingTicker) { | ||
this.sleepingTicker = sleepingTicker; | ||
} | ||
|
||
@Override | ||
public boolean lithium$startSleeping() { | ||
if (this.isSleeping()) { | ||
return false; | ||
} | ||
|
||
WrappedBlockEntityTickInvokerAccessor tickWrapper = this.lithium$getTickWrapper(); | ||
if (tickWrapper != null) { | ||
this.lithium$setSleepingTicker(tickWrapper.getWrapped()); | ||
tickWrapper.callSetWrapped(SleepingBlockEntity.SLEEPING_BLOCK_ENTITY_TICKER); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setWorld(World world) { | ||
super.setWorld(world); | ||
lithium$startSleeping(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...main/java/com/github/tatercertified/fabricautocrafter/mixin/LithiumSleepControlMixin.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,29 @@ | ||
package com.github.tatercertified.fabricautocrafter.mixin; | ||
|
||
import com.github.tatercertified.fabricautocrafter.AutoCraftingTableBlockEntity; | ||
import com.github.tatercertified.fabricautocrafter.AutoCraftingTableContainer; | ||
import com.moulberry.mixinconstraints.annotations.IfModLoaded; | ||
import me.jellysquid.mods.lithium.common.block.entity.SleepingBlockEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@IfModLoaded(value = "lithium") | ||
@Mixin(AutoCraftingTableContainer.class) | ||
public class LithiumSleepControlMixin { | ||
|
||
@Shadow | ||
AutoCraftingTableBlockEntity blockEntity; | ||
|
||
@Inject(method = "onContentChanged", at = @At("TAIL")) | ||
public void injectSleep(CallbackInfo ci) { | ||
((SleepingBlockEntity)blockEntity).lithium$startSleeping(); | ||
} | ||
|
||
@Inject(method = "onContentChanged", at = @At("HEAD")) | ||
public void injectWakeUp(CallbackInfo ci) { | ||
((SleepingBlockEntity)blockEntity).wakeUpNow(); | ||
} | ||
} |
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