-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
626 additions
and
1 deletion.
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
100 changes: 100 additions & 0 deletions
100
src/main/java/com/github/ptom76/tutorialfabricmod/block/BlueAppleGenerator.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,100 @@ | ||
package com.github.ptom76.tutorialfabricmod.block; | ||
|
||
import com.github.ptom76.tutorialfabricmod.tile.BlueAppleGeneratorTile; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockEntityProvider; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityTicker; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.DirectionProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.ItemScatterer; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BlueAppleGenerator extends Block implements BlockEntityProvider { | ||
|
||
// 東西南北の方向性 | ||
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; | ||
|
||
public BlueAppleGenerator(Settings settings) { | ||
super(settings); | ||
setDefaultState(getDefaultState().with(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Override | ||
public void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(FACING); | ||
super.appendProperties(builder); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return super.getPlacementState(ctx).with(FACING, ctx.getPlayer().getHorizontalFacing().getOpposite()); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new BlueAppleGeneratorTile(pos, state); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
// ブロックを右クリックした時に呼び出される関数 | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
if (world.isClient) return ActionResult.SUCCESS; | ||
BlockEntity tile = world.getBlockEntity(pos); | ||
if (tile instanceof BlueAppleGeneratorTile) { | ||
BlueAppleGeneratorTile blueAppleGeneratorTile = (BlueAppleGeneratorTile) tile; | ||
|
||
// GUIを開く | ||
player.openHandledScreen(blueAppleGeneratorTile); | ||
|
||
return ActionResult.SUCCESS; | ||
} | ||
|
||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return (world1, pos, state1, tile) -> { | ||
if (tile instanceof BlueAppleGeneratorTile) { | ||
BlueAppleGeneratorTile blueAppleGeneratorTile = (BlueAppleGeneratorTile) tile; | ||
blueAppleGeneratorTile.tick(world1, pos, state1, blueAppleGeneratorTile); | ||
} | ||
}; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { | ||
if (state.isOf(newState.getBlock())) { | ||
return; | ||
} | ||
BlockEntity blockEntity = world.getBlockEntity(pos); | ||
if (blockEntity instanceof Inventory) { | ||
Inventory inventory = (Inventory) blockEntity; | ||
|
||
// アイテムをドロップさせる | ||
ItemScatterer.spawn(world, pos, inventory); | ||
|
||
// コンパレータの更新 | ||
world.updateComparators(pos, this); | ||
} | ||
super.onStateReplaced(state, world, pos, newState, moved); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/github/ptom76/tutorialfabricmod/block/ClickCountBlock.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,72 @@ | ||
package com.github.ptom76.tutorialfabricmod.block; | ||
|
||
import com.github.ptom76.tutorialfabricmod.tile.ClickCountBlockTile; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockEntityProvider; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.DirectionProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ClickCountBlock extends Block implements BlockEntityProvider { | ||
|
||
// 東西南北の方向性 | ||
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; | ||
|
||
public ClickCountBlock(Settings settings) { | ||
super(settings); | ||
setDefaultState(getDefaultState().with(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Override | ||
public void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(FACING); | ||
super.appendProperties(builder); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return super.getPlacementState(ctx).with(FACING, ctx.getPlayer().getHorizontalFacing().getOpposite()); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new ClickCountBlockTile(pos, state); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
// ブロックを右クリックした時に呼び出される関数 | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
BlockEntity tile = world.getBlockEntity(pos); | ||
if (tile instanceof ClickCountBlockTile) { | ||
ClickCountBlockTile clickCountBlockTile = (ClickCountBlockTile) tile; | ||
|
||
if (player.isSneaking()) { | ||
// プレイヤーにメッセージを送る | ||
if (!world.isClient) | ||
player.sendMessage(Text.literal("クリックした回数: " + clickCountBlockTile.getClickCount())); | ||
return ActionResult.SUCCESS; | ||
} | ||
|
||
// クリック回数を増やす | ||
clickCountBlockTile.increaseClickCount(); | ||
return ActionResult.SUCCESS; | ||
} | ||
|
||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...main/java/com/github/ptom76/tutorialfabricmod/client/screen/BlueAppleGeneratorScreen.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,38 @@ | ||
package com.github.ptom76.tutorialfabricmod.client.screen; | ||
|
||
import com.github.ptom76.tutorialfabricmod.TutorialFabricMod; | ||
import com.github.ptom76.tutorialfabricmod.screenhandler.BlueAppleGeneratorScreenHandler; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.render.GameRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class BlueAppleGeneratorScreen extends HandledScreen<BlueAppleGeneratorScreenHandler> { | ||
// assets/tutorialfabricmod/textures/gui/container/blue_apple_generator.png | ||
private static final Identifier TEXTURE = TutorialFabricMod.id("textures/gui/container/blue_apple_generator.png"); | ||
|
||
public BlueAppleGeneratorScreen(BlueAppleGeneratorScreenHandler handler, PlayerInventory inventory, Text title) { | ||
super(handler, inventory, title); | ||
} | ||
|
||
@Override | ||
public void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { | ||
//RenderSystem.setShader(GameRenderer::getPositionTexShader); 1.19.2以前 | ||
RenderSystem.setShader(GameRenderer::getPositionTexProgram); | ||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); | ||
RenderSystem.setShaderTexture(0, TEXTURE); | ||
int x = (width - backgroundWidth) / 2; | ||
int y = (height - backgroundHeight) / 2; | ||
drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight); | ||
} | ||
|
||
@Override | ||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { | ||
renderBackground(matrices); | ||
super.render(matrices, mouseX, mouseY, delta); | ||
drawMouseoverTooltip(matrices, mouseX, mouseY); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/github/ptom76/tutorialfabricmod/client/screen/Screens.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,12 @@ | ||
package com.github.ptom76.tutorialfabricmod.client.screen; | ||
|
||
import com.github.ptom76.tutorialfabricmod.screenhandler.ScreenHandlers; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreens; | ||
|
||
public class Screens { | ||
|
||
public static void init() { | ||
// スクリーンの登録 | ||
HandledScreens.register(ScreenHandlers.BLUE_APPLE_GENERATOR_SCREEN_HANDLER, BlueAppleGeneratorScreen::new); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/github/ptom76/tutorialfabricmod/inventory/IInventory.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,77 @@ | ||
package com.github.ptom76.tutorialfabricmod.inventory; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.inventory.Inventories; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.collection.DefaultedList; | ||
|
||
public interface IInventory extends Inventory { | ||
|
||
DefaultedList<ItemStack> getItems(); | ||
|
||
static IInventory of(DefaultedList<ItemStack> items) { | ||
return () -> items; | ||
} | ||
|
||
static IInventory ofSize(int size) { | ||
return of(DefaultedList.ofSize(size, ItemStack.EMPTY)); | ||
} | ||
|
||
@Override | ||
default int size() { | ||
return getItems().size(); | ||
} | ||
|
||
@Override | ||
default boolean isEmpty() { | ||
for (int i = 0; i < size(); i++) { | ||
ItemStack stack = getStack(i); | ||
if (!stack.isEmpty()) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
default ItemStack getStack(int slot) { | ||
return getItems().get(slot); | ||
} | ||
|
||
@Override | ||
default ItemStack removeStack(int slot, int count) { | ||
ItemStack result = Inventories.splitStack(getItems(), slot, count); | ||
if (!result.isEmpty()) { | ||
markDirty(); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
default ItemStack removeStack(int slot) { | ||
return Inventories.removeStack(getItems(), slot); | ||
} | ||
|
||
@Override | ||
default void setStack(int slot, ItemStack stack) { | ||
getItems().set(slot, stack); | ||
if (stack.getCount() > getMaxCountPerStack()) { | ||
stack.setCount(getMaxCountPerStack()); | ||
} | ||
} | ||
|
||
@Override | ||
default void clear() { | ||
getItems().clear(); | ||
} | ||
|
||
@Override | ||
default void markDirty() { | ||
} | ||
|
||
@Override | ||
default boolean canPlayerUse(PlayerEntity player) { | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.