-
Notifications
You must be signed in to change notification settings - Fork 945
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ComputerCraft integration to Stickers
- Add CC isExtended() function to check extension state - Add CC extend()/retract()/toggle() to change the Sticker extension state, returning state change success.
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
...om/simibubi/create/compat/computercraft/implementation/peripherals/StickerPeripheral.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,62 @@ | ||
package com.simibubi.create.compat.computercraft.implementation.peripherals; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
|
||
import com.simibubi.create.AllBlocks; | ||
import com.simibubi.create.content.contraptions.chassis.StickerBlock; | ||
import com.simibubi.create.content.contraptions.chassis.StickerBlockEntity; | ||
|
||
import dan200.computercraft.api.lua.LuaFunction; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class StickerPeripheral extends SyncedPeripheral<StickerBlockEntity> { | ||
|
||
public StickerPeripheral(StickerBlockEntity blockEntity) { | ||
super(blockEntity); | ||
} | ||
|
||
@LuaFunction | ||
public boolean isExtended() { | ||
return blockEntity.isBlockStateExtended(); | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public boolean extend() { | ||
BlockState state = blockEntity.getBlockState(); | ||
if (!AllBlocks.STICKER.has(state) || state.getValue(StickerBlock.EXTENDED)) | ||
return false; | ||
blockEntity.getLevel().setBlock( | ||
blockEntity.getBlockPos(), state.setValue(StickerBlock.EXTENDED, true), Block.UPDATE_CLIENTS); | ||
return true; | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public boolean retract() { | ||
BlockState state = blockEntity.getBlockState(); | ||
if (!AllBlocks.STICKER.has(state) || !state.getValue(StickerBlock.EXTENDED)) | ||
return false; | ||
blockEntity.getLevel().setBlock( | ||
blockEntity.getBlockPos(), state.setValue(StickerBlock.EXTENDED, false), Block.UPDATE_CLIENTS); | ||
return true; | ||
} | ||
|
||
@LuaFunction(mainThread = true) | ||
public boolean toggle() { | ||
BlockState state = blockEntity.getBlockState(); | ||
if (!AllBlocks.STICKER.has(state)) | ||
return false; | ||
boolean extended = state.getValue(StickerBlock.EXTENDED); | ||
blockEntity.getLevel().setBlock( | ||
blockEntity.getBlockPos(), state.setValue(StickerBlock.EXTENDED, !extended), Block.UPDATE_CLIENTS); | ||
return true; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getType() { | ||
return "Create_Sticker"; | ||
} | ||
|
||
} |
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