Skip to content

Commit

Permalink
Changes by SEYUISEDRGYHUISERFGHUYIRGDEFSHERGUISDHUIERGSDHUISEDRGHUIDE…
Browse files Browse the repository at this point in the history
…FGRS
  • Loading branch information
ThomasBeHappy committed Jul 14, 2024
1 parent f21600e commit eeade7c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,97 @@ public LaserFocuserBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}


@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}

@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
return VoxelShapes.fullCube();
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new LaserFocuserBlockEntity(pos, state);
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof LaserFocuserBlockEntity) {
ItemScatterer.spawn(world, pos, (LaserFocuserBlockEntity)blockEntity);
world.updateComparators(pos,this);
}
super.onStateReplaced(state, world, pos, newState, moved);
}
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack playerStack = player.getStackInHand(hand);

BlockEntity entity = world.getBlockEntity(pos);

if (entity instanceof LaserFocuserBlockEntity be) {
ItemStack beStack = be.getStack(0);

Item playerItem = playerStack.getItem();
if (beStack.getItem() != Items.AIR) {
if (Recipes.isValidRecipe(playerItem)) {
player.setStackInHand(hand, beStack);
be.setStack(0, playerStack);
} else {
if (playerItem == Items.AIR) {
player.setStackInHand(hand, beStack);
}else {
if (!player.giveItemStack(beStack)) {
Vec3d playerPos = player.getPos();
ItemScatterer.spawn(world, playerPos.x, playerPos.y, playerPos.z, beStack);
}
}
be.setStack(0, Items.AIR.getDefaultStack());
}
} else {
if (Recipes.isValidRecipe(playerItem)) {
player.setStackInHand(hand, Items.AIR.getDefaultStack());
be.setStack(0, playerStack);
}
}
}

// player.openHandledScreen(state.createScreenHandlerFactory(world, pos));
return ActionResult.SUCCESS;
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
if (type != ModBlockEntities.LASER_FOCUSER_BLOCK_ENTITY) return null;
return (world1, pos, state1, be) -> ((LaserFocuserBlockEntity)be).tick(world1, pos, state1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.Recipe;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.screen.PropertyDelegate;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/gamingframe/beamtech/screens/ModGUIs.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class ModGUIs {
new ScreenHandlerType<>((syncId, inventory) -> new EmitterGUI(syncId, inventory, ScreenHandlerContext.EMPTY),
FeatureFlags.VANILLA_FEATURES));

public static final ScreenHandlerType<LaserOvenGUI> LASER_OVEN_GUI = Registry.register(Registries.SCREEN_HANDLER, Identifier.of(BeamTech.MOD_ID, "laser_oven_screen"),
new ScreenHandlerType<>((syncId, inventory) -> new LaserOvenGUI(syncId, inventory, ScreenHandlerContext.EMPTY),
FeatureFlags.VANILLA_FEATURES));


public static void InitializeGUIs() {
BeamTech.LOGGER.info("Initializing Screens for {}", BeamTech.MOD_ID);
Expand Down

0 comments on commit eeade7c

Please sign in to comment.