Skip to content

Instantly share code, notes, and snippets.

@nnnnusui
Last active March 23, 2020 02:17
Show Gist options
  • Save nnnnusui/5c015bbd94949d22c938b6f76694aa48 to your computer and use it in GitHub Desktop.
Save nnnnusui/5c015bbd94949d22c938b6f76694aa48 to your computer and use it in GitHub Desktop.
minecraft forge 1.15.2-31.0.1 _ シフトクリックすると設置方角が変わるドア
package com.example;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.TallBlockItem;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ObjectHolder;
@Mod.EventBusSubscriber(modid = modId, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(modId)
public class BlockRegister {
private static OriginalDoorBlock originalDoorBlock = new OriginalDoorBlock();
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event){
event.getRegistry().registerAll(
new BlockItem(originalDoorBlock, new Item.Properties()).setRegistryName(modId, OriginalDoorBlock.registryName)
);
}
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event){
event.getRegistry().registerAll(
originalDoorBlock
);
}
}
package com.example;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World;
public class OriginalDoorBlock extends DoorBlock {
static final String registryName = "original_door";
protected OriginalDoorBlock() {
super(Properties.create(Material.PLANTS));
setRegistryName(NotEnoughMaterials.modId, registryName);
}
// 難読化されたままだが、右クリック時の動作を書き換えるためにこれを用いる。
@Override
public ActionResultType func_225533_a_(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand p_225533_5_, BlockRayTraceResult p_225533_6_) {
if(!player.isCrouching())
return super.func_225533_a_(state, worldIn, pos, player, p_225533_5_, p_225533_6_);
Direction facing = state.get(FACING);
BlockState updated = state.with(FACING, facing.rotateY());
worldIn.setBlockState(pos, updated);
return ActionResultType.SUCCESS;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment