Skip to content

Instantly share code, notes, and snippets.

@tryashtar
Created March 2, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tryashtar/0369d902aafec92d81fadf56dbce01d3 to your computer and use it in GitHub Desktop.
Save tryashtar/0369d902aafec92d81fadf56dbce01d3 to your computer and use it in GitHub Desktop.
Old piston code
scoreboard players set @a length 0
stats entity @a[score_sneaking_min=1] set AffectedBlocks @p length
execute @a[score_sneaking_min=1] ~ ~ ~ testforblock ~ ~-.1 ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b}]}
stats entity @a[score_sneaking_min=1] clear AffectedBlocks
execute @e[type=ArmorStand,name=LPBase] ~ ~.5 ~ scoreboard players set @a[r=1] length 0
execute @a[score_length_min=1] ~ ~ ~ summon LeashKnot ~ ~-1 ~ {CustomName:PSTstu}
execute @a[score_length_min=1] ~ ~ ~ blockdata ~ ~-.1 ~ {CustomName:Extended Piston}
execute @e[type=LeashKnot,name=PSTstu] ~ ~ ~ particle snowballpoof ~ ~.55 ~ .2 .1 .2 .02 30
execute @e[type=LeashKnot,name=PSTstu] ~ ~ ~ playsound block.anvil.place block @a ~ ~ ~ 1 .3
execute @e[type=LeashKnot,name=PSTstu] ~ ~ ~ summon ArmorStand ~ ~ ~ {Invisible:1,Marker:1,NoGravity:1,CustomName:LPBase}
kill @e[type=LeashKnot,name=PSTstu]
scoreboard players set @e[type=ArmorStand,name=LPBase] direction 0
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 0 scoreboard players set @e[type=ArmorStand,c=1] direction 1
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 8 scoreboard players set @e[type=ArmorStand,c=1] direction 2
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 1 scoreboard players set @e[type=ArmorStand,c=1] direction 3
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 9 scoreboard players set @e[type=ArmorStand,c=1] direction 4
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 2 scoreboard players set @e[type=ArmorStand,c=1] direction 5
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 10 scoreboard players set @e[type=ArmorStand,c=1] direction 6
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 3 scoreboard players set @e[type=ArmorStand,c=1] direction 7
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 11 scoreboard players set @e[type=ArmorStand,c=1] direction 8
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 4 scoreboard players set @e[type=ArmorStand,c=1] direction 9
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 12 scoreboard players set @e[type=ArmorStand,c=1] direction 10
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 5 scoreboard players set @e[type=ArmorStand,c=1] direction 11
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ detect ~ ~ ~ dropper 13 scoreboard players set @e[type=ArmorStand,c=1] direction 12
execute @e[type=ArmorStand,name=LPBase,score_direction=0] ~ ~ ~ particle smoke ~ ~ ~ .15 .15 .15 .05 60
execute @e[type=ArmorStand,name=LPBase,score_direction=0] ~ ~ ~ playsound entity.item.break block @a ~ ~ ~.5 1 .5
kill @e[type=ArmorStand,name=LPBase,score_direction=0]
scoreboard players set @e[type=ArmorStand,name=LPBase] length 0
scoreboard players set @e[type=ArmorStand,name=LPBase] sneaking 0
stats entity @e[type=ArmorStand,name=LPBase] set AffectedBlocks @e[type=ArmorStand,c=1] sneaking
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:1b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 1
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:2b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 2
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:3b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 3
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:4b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 4
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:5b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 5
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:6b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 6
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:7b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 7
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:8b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 8
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:9b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 9
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:10b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 10
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:11b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 11
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:12b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 12
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:13b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 13
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:14b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 14
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ testforblock ~ ~ ~ dropper -1 {Items:[{id:minecraft:piston,Slot:4b,Count:15b}]}
scoreboard players set @e[type=ArmorStand,name=LPBase,score_sneaking_min=1] length 15
scoreboard players tag @e[type=ArmorStand,name=LPBase] remove PSTpwd
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,c=1] sneaking = @e[type=ArmorStand,c=1] direction
execute @e[type=ArmorStand,name=LPBase] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,c=1] sneaking %= constants length
scoreboard players tag @e[type=ArmorStand,name=LPBase,score_sneaking=0] add PSTpwd
// alright, the direction is saved in a score
// the length is saved in a score
// the power state is saved in a tag
// powertime increases while it's powered and is zero when unpowered
// when powertime=1, it just received power
scoreboard players set @e[type=ArmorStand,name=LPBase,tag=!PSTpwd] powertime 0
scoreboard players add @e[type=ArmorStand,name=LPBase,tag=PSTpwd] powertime 1
scoreboard players add @e[type=ArmorStand,name=LPBase,score_powertime_min=1,score_powertime=1] killprop 5
scoreboard players remove @e[type=ArmorStand,name=LPBase,score_killprop_min=1] killprop 1
execute @e[type=ArmorStand,name=LPBase,score_killprop_min=1] ~ ~ ~ scoreboard players tag @e[type=Item,r=1,c=1] add pistitem {Item:{id:minecraft:piston,Count:1b},PickupDelay:0s,Age:0s}
execute @e[type=ArmorStand,name=LPBase,score_killprop_min=1] ~ ~ ~ kill @e[type=Item,tag=pistitem,r=1,c=1]
// if the base is powered but not extended, create an extension
execute @e[type=ArmorStand,name=LPBase,score_powertime_min=1,tag=!extended] ~ ~ ~ summon ArmorStand ~ ~ ~ {Marker:1b,Invisible:1b,NoGravity:1b,CustomName:LPExtension,Tags:["newextension"]}
execute @e[type=ArmorStand,name=LPBase,score_powertime_min=1,tag=!extended] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,name=LPExtension,r=1,c=1] killprop = @e[type=ArmorStand,c=1] length
execute @e[type=ArmorStand,name=LPBase,score_powertime_min=1,tag=!extended] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,name=LPExtension,r=1,c=1] length = @e[type=ArmorStand,c=1] length
execute @e[type=ArmorStand,name=LPBase,score_powertime_min=1,tag=!extended] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,name=LPExtension,r=1,c=1] direction = @e[type=ArmorStand,c=1] direction
scoreboard players tag @e[type=ArmorStand,name=LPBase,score_powertime_min=1,tag=!extended] add extended
execute @e[type=ArmorStand,name=LPExtension,tag=!newextension] ~ ~ ~ setblock ~ ~ ~ cobblestone_wall
tp @e[type=ArmorStand,name=LPExtension,score_direction_min=1,score_direction=2] ~ ~-1 ~
tp @e[type=ArmorStand,name=LPExtension,score_direction_min=3,score_direction=4] ~ ~1 ~
tp @e[type=ArmorStand,name=LPExtension,score_direction_min=5,score_direction=6] ~ ~ ~-1
tp @e[type=ArmorStand,name=LPExtension,score_direction_min=7,score_direction=8] ~ ~ ~1
tp @e[type=ArmorStand,name=LPExtension,score_direction_min=9,score_direction=10] ~-1 ~ ~
tp @e[type=ArmorStand,name=LPExtension,score_direction_min=11,score_direction=12] ~1 ~ ~
scoreboard players tag @e[type=ArmorStand,name=LPExtension] remove freespot
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ air 0 scoreboard players tag @e[type=ArmorStand,c=1] add freespot
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ bedrock -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ barrier -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ structure_void -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ piston_extension -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ piston_head -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ portal -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ end_portal -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ end_portal_frame -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ cobblestone_wall -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ structure_block -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ command_block -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ chain_command_block -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ repeating_command_block -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
execute @e[type=ArmorStand,name=LPExtension] ~ ~ ~ detect ~ ~ ~ end_gateway -1 scoreboard players tag @e[type=ArmorStand,c=1] add illegalpos
scoreboard players set @e[type=ArmorStand,name=LPExtension] sneaking 0
stats entity @e[type=ArmorStand,name=LPExtension] set AffectedBlocks @e[type=ArmorStand,c=1] sneaking
execute @e[type=ArmorStand,name=LPExtension,score_direction_min=1,score_direction=2,tag=!illegalpos] ~ ~ ~ detect ~ ~-1 ~ air 0 clone ~ ~ ~ ~ ~ ~ ~ ~-1 ~
execute @e[type=ArmorStand,name=LPExtension,score_direction_min=3,score_direction=4,tag=!illegalpos] ~ ~ ~ detect ~ ~1 ~ air 0 clone ~ ~ ~ ~ ~ ~ ~ ~1 ~
execute @e[type=ArmorStand,name=LPExtension,score_direction_min=5,score_direction=6,tag=!illegalpos] ~ ~ ~ detect ~ ~ ~-1 air 0 clone ~ ~ ~ ~ ~ ~ ~ ~ ~-1
execute @e[type=ArmorStand,name=LPExtension,score_direction_min=7,score_direction=8,tag=!illegalpos] ~ ~ ~ detect ~ ~ ~1 air 0 clone ~ ~ ~ ~ ~ ~ ~ ~ ~1
execute @e[type=ArmorStand,name=LPExtension,score_direction_min=9,score_direction=10,tag=!illegalpos] ~ ~ ~ detect ~-1 ~ ~ air 0 clone ~ ~ ~ ~ ~ ~ ~-1 ~ ~
execute @e[type=ArmorStand,name=LPExtension,score_direction_min=11,score_direction=12,tag=!illegalpos] ~ ~ ~ detect ~1 ~ ~ air 0 clone ~ ~ ~ ~ ~ ~ ~1 ~ ~
stats entity @e[type=ArmorStand,name=LPExtension] clear AffectedBlocks
scoreboard players tag @e[type=ArmorStand,name=LPExtension,tag=illegalpos] add beginretract
scoreboard players tag @e[type=ArmorStand,name=LPExtension,score_sneaking=0,tag=!freespot] add beginretract
tp @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1,score_direction_min=1,score_direction=2] ~ ~1 ~
tp @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1,score_direction_min=3,score_direction=4] ~ ~-1 ~
tp @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1,score_direction_min=5,score_direction=6] ~ ~ ~1
tp @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1,score_direction_min=7,score_direction=8] ~ ~ ~-1
tp @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1,score_direction_min=9,score_direction=10] ~1 ~ ~
tp @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1,score_direction_min=11,score_direction=12] ~-1 ~ ~
scoreboard players remove @e[type=ArmorStand,name=LPExtension] length 1
scoreboard players tag @e[type=ArmorStand,name=LPExtension,score_length=0] add beginretract
scoreboard players tag @e[type=ArmorStand,name=LPExtension,tag=newextension] add quickstop {Tags:["beginretract"]}
execute @e[type=ArmorStand,name=LPExtension,tag=!quickstop] ~ ~ ~ setblock ~ ~ ~ planks
scoreboard players tag @e[type=ArmorStand,name=LPExtension,tag=newextension] remove newextension
// we are changing this to behave differently
// scoreboard players add @e[type=ArmorStand,name=LPExtension,tag=beginretract,score_length_min=1] length 1
// execute @e[type=ArmorStand,name=LPExtension,tag=beginretract] ~ ~ ~ summon ArmorStand ~ ~ ~ {Marker:1b,Invisible:1b,NoGravity:1b,CustomName:LPRetraction}
// execute @e[type=ArmorStand,name=LPExtension,tag=beginretract] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,name=LPRetraction,r=1,c=1] direction = @e[type=ArmorStand,c=1] retraction
// execute @e[type=ArmorStand,name=LPExtension,tag=beginretract] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,name=LPRetraction,r=1,c=1] length = @e[type=ArmorStand,c=1] killprop
// execute @e[type=ArmorStand,name=LPExtension,tag=beginretract] ~ ~ ~ scoreboard players operation @e[type=ArmorStand,name=LPRetraction,r=1,c=1] length -= @e[type=ArmorStand,c=1] length
// okay, at this point, the retraction is in STANDBY
// kill @e[type=ArmorStand,name=LPExtension,tag=beginretract]
// UNIMPLEMENTED FEATURES:
// the piston should continue to "push" until its entire length is exhausted
// if it is blocked by two blocks or an illegal thing, it won't move
// but if the obstruction is removed, it will continue forward
// thus, the retraction should ONLY be created when the dropper is unpowered
// if the extension has no length or is obstructed, it performs no teleports or clones until it is given permission (when the obstruction is removed)
// CURRENT ISSUES: (not unimplemented features)
// ISSUES PRESENT IN OLD VERSION:
// item not killed when it has exactly 15
// retraction continues forever (it doesn't care about length)
// dropper breakable while extended
// can push the planks/walls/dropper of other pistons with long pistons or normal pistons
// items can be put in different slots and will be fired instead of the pistons
// very fast power-unpower with one item does not extend, just spits the item out
scoreboard players set @a[score_sneaking_min=1] sneaking 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment