parent
14d79f9491
commit
8832d6a300
|
@ -1,13 +1,16 @@
|
|||
package modchest;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class REServerModClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
public class REServerModClient implements ClientModInitializer{
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package modchest.block.custom;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.texture.AbstractTexture;
|
||||
import net.minecraft.client.texture.ResourceTexture;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class gridBlockTexture extends TextureManager {
|
||||
|
||||
|
||||
public gridBlockTexture(ResourceManager resourceManager) {
|
||||
super(resourceManager);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public BlockState getGridBlockState(Block gridBlock){ //nötig wegen static / non-static
|
||||
BlockState gridBlockState= gridBlock.getDefaultState();
|
||||
return gridBlockState;
|
||||
}
|
||||
|
||||
|
||||
private final Map<Identifier, AbstractTexture> textures = Maps.newHashMap();
|
||||
|
||||
public AbstractTexture getGridBlockTexture(Block gridBlock) {
|
||||
Identifier id = Registry.BLOCK.getId(gridBlock);
|
||||
|
||||
AbstractTexture gridBlockTexture = (AbstractTexture)this.textures.get(id);
|
||||
if (gridBlockTexture == null) {
|
||||
gridBlockTexture = new ResourceTexture(id);
|
||||
this.registerTexture(id, (AbstractTexture)gridBlockTexture);
|
||||
}
|
||||
return gridBlockTexture;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package modchest.rendering;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.render.block.BlockModels;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.item.BuiltinModelItemRenderer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class gridBlockEntityRenderer extends BlockRenderManager {
|
||||
|
||||
public gridBlockEntityRenderer(BlockModels models, BuiltinModelItemRenderer builtinModelItemRenderer,
|
||||
BlockColors blockColors) {
|
||||
super(models, builtinModelItemRenderer, blockColors);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/*private static final int WIDTH = 16;
|
||||
private static final int HEIGHT = 16;
|
||||
private static final int ROTATIONS = 16;
|
||||
|
||||
public gridBlockEntityRenderer(BlockModels models, BuiltinModelItemRenderer builtinModelItemRenderer, BlockColors blockColors) {
|
||||
super(models, builtinModelItemRenderer, blockColors);
|
||||
}
|
||||
|
||||
private Sprite customTexture;
|
||||
|
||||
// Hier kannst du das Rendering der Block-Entität anpassen
|
||||
// Zum Beispiel, um eine benutzerdefinierte Textur anzuwenden
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void renderBlock(BlockState state, BlockPos pos, BlockRenderView world, MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random) {
|
||||
try {
|
||||
BlockRenderType blockRenderType = state.getRenderType();
|
||||
if (blockRenderType == BlockRenderType.MODEL) {
|
||||
this.blockModelRenderer.render(world, this.getModel(state), state, pos, matrices, vertexConsumer, cull, random, state.getRenderingSeed(pos), OverlayTexture.DEFAULT_UV);
|
||||
}
|
||||
|
||||
} catch (Throwable var11) {
|
||||
CrashReport crashReport = CrashReport.create(var11, "Tesselating block in world");
|
||||
CrashReportSection crashReportSection = crashReport.addElement("Block being tesselated");
|
||||
CrashReportSection.addBlockInfo(crashReportSection, world, pos, state);
|
||||
throw new CrashException(crashReport);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
gridBlockAttackCallback
|
||||
|
||||
in modBlockEntities neuer BlockEntityType GRID_BLOCK_ENTITY
|
||||
- funktioniert nicht mit gridBlockEntityRenderer und REServerModClient
|
||||
|
||||
//REServerModClient: registrieren gridBlockEntityRenderer
|
||||
|
||||
gridBlock: createBlockEntity
|
||||
|
||||
gridBlockEntity:
|
||||
- render() funktioniert kann nicht überschrieben werden
|
||||
- gelöscht
|
||||
|
||||
gridBlockEntityRenderer:
|
||||
- render()
|
||||
- textureManager ist die KLasse die wir brauchen -> client
|
||||
|
||||
|
||||
BlockRenderManager: kann getModel!!!!!
|
||||
- client
|
||||
|
||||
gridBlockTexture: extends TextureManager
|
||||
- getTexture(IdentifierID)
|
||||
- PROBLEM: wie in useBlockCallback/gridBlockEntity auf Server??
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package modchest;
|
||||
|
||||
import modchest.block.entity.modBlockEntities;
|
||||
import modchest.event.attackBlockCallback;
|
||||
|
||||
import modchest.event.useBlockCallback;
|
||||
import modchest.block.modBlocks;
|
||||
import modchest.item.modItemGroup;
|
||||
|
@ -24,7 +24,7 @@ public class REServerMod implements ModInitializer {
|
|||
modBlocks.setBlocks(); // Hier werden die Blöcke erstellt
|
||||
modBlockEntities.registerBlockEntities(); // Die Interaktionsmenüs für die Blöcke werden erstellt
|
||||
useBlockCallback.EVENT.register(new useBlockCallback());
|
||||
attackBlockCallback.EVENT.register(new attackBlockCallback());
|
||||
|
||||
|
||||
LOGGER.info("Modchest erfolgreich geladen!");
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package modchest.block.custom;
|
||||
|
||||
|
||||
import modchest.block.entity.gridBlockEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
public class gridBlock extends Block {
|
||||
|
||||
BlockState state;
|
||||
public class gridBlock extends Block implements BlockEntityProvider{
|
||||
|
||||
public gridBlock(Settings settings) {
|
||||
|
||||
public gridBlock(final Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -17,6 +22,14 @@ public class gridBlock extends Block {
|
|||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
|
||||
return super.isSideInvisible(state, stateFrom, direction) || (state == stateFrom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new gridBlockEntity(pos, state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package modchest.block.entity;
|
||||
|
||||
public interface BlockEntityClientSerializable {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package modchest.block.entity;
|
||||
|
||||
public class TranslatableText {
|
||||
|
||||
}
|
|
@ -10,58 +10,53 @@ import net.minecraft.screen.PropertyDelegate;
|
|||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
public class gridBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory {
|
||||
public class gridBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory{
|
||||
|
||||
public final PropertyDelegate propertyDelegate;
|
||||
|
||||
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(3, ItemStack.EMPTY);
|
||||
public gridBlockEntity( BlockPos pos, BlockState state) {
|
||||
super(modBlockEntities.GRID_BLOCK_ENTITY, pos, state);
|
||||
this.propertyDelegate = new PropertyDelegate() {
|
||||
@Override
|
||||
public int get(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, int value) {
|
||||
|
||||
}
|
||||
|
||||
public gridBlockEntity(BlockPos pos, BlockState state){
|
||||
super (modBlockEntities.grid_block_interface, pos, state);
|
||||
this.propertyDelegate = new PropertyDelegate() {
|
||||
@Override
|
||||
public int get(int index) {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, int value) {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int arg0, PlayerInventory arg1, PlayerEntity arg2) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'createMenu'");
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public DefaultedList<ItemStack> getItems() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getItems'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void registerBlockEntities2(){}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultedList<ItemStack> getItems() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return Text.literal("Grid Block");
|
||||
} //TODO: setzt den Namen. Muss noch an die einzelnen Sprachen angepasst werden!
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getDisplayName'");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,20 +9,17 @@ import net.minecraft.util.registry.Registry;
|
|||
|
||||
//rendert letztendlich die Interaktionsmenüs der Blöcke
|
||||
public class modBlockEntities {
|
||||
public static BlockEntityType<steeringWheelEntity> steering_wheel_interface; // Interaktionsmenü wird erstellt
|
||||
public static BlockEntityType<steeringWheelEntity> steering_wheel_interface;// Interaktionsmenü wird erstellt
|
||||
public static BlockEntityType<gridBlockEntity> GRID_BLOCK_ENTITY;
|
||||
|
||||
|
||||
public static void registerBlockEntities() {
|
||||
steering_wheel_interface = Registry.register(Registry.BLOCK_ENTITY_TYPE,
|
||||
new Identifier(REServerMod.MOD_ID, "steering_wheel_interface"), // Interkationsmenü wird gerendert
|
||||
FabricBlockEntityTypeBuilder.create(steeringWheelEntity::new, modBlocks.steering_wheel).build(null));
|
||||
}
|
||||
|
||||
|
||||
public static BlockEntityType<gridBlockEntity> grid_block_interface;
|
||||
|
||||
public static void registerBlockEntities2() {
|
||||
grid_block_interface = Registry.register(Registry.BLOCK_ENTITY_TYPE,
|
||||
new Identifier(REServerMod.MOD_ID, "grid_block_interface"),
|
||||
GRID_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE,
|
||||
new Identifier(REServerMod.MOD_ID, "grid_block_entity"),
|
||||
FabricBlockEntityTypeBuilder.create(gridBlockEntity::new, modBlocks.grid_block).build(null));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class modBlocks {
|
|||
new steeringWheelBlock(FabricBlockSettings.of(Material.WOOD).strength(1.0f).requiresTool()),
|
||||
modItemGroup.modchest);
|
||||
|
||||
grid_block = registerBlock("grid_block",
|
||||
grid_block = registerBlock("grid_block",
|
||||
new gridBlock(FabricBlockSettings.of(Material.WOOD).strength(1.0f).requiresTool()),
|
||||
modItemGroup.modchest);
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package modchest.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class attackBlockCallback implements AttackBlockCallback{
|
||||
|
||||
@Override
|
||||
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||
|
||||
|
||||
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package modchest.event;
|
||||
|
||||
import modchest.block.entity.gridBlockEntity;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Position;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public interface gridBlockAttackCallback {
|
||||
|
||||
Event<gridBlockAttackCallback> EVENT = EventFactory.createArrayBacked(gridBlockAttackCallback.class,
|
||||
(listeners) -> (player, gridBlock, hand, pos, direction, hitResult) -> {
|
||||
for (gridBlockAttackCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, gridBlock, hand, pos, direction, hitResult);
|
||||
|
||||
if(result != ActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, gridBlockEntity gridBlock, Hand hand, Position pos, Direction direction, BlockHitResult hitResult);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,42 +2,48 @@ package modchest.event;
|
|||
|
||||
import static net.minecraft.block.Block.getBlockFromItem;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.OverrideOnly;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import modchest.block.custom.gridBlock;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stat.Stat;
|
||||
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.BlockRenderView;
|
||||
import net.minecraft.util.math.Position;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
import net.minecraft.world.event.GameEvent.Emitter;
|
||||
|
||||
public class useBlockCallback implements UseBlockCallback {
|
||||
|
||||
//wird aufgerufen, wenn ein Block "rechtsgeklickt" wird; überprüft, ob das mit einem gridBlock passiert, wenn ja wird der Block zu einem gridBlock geändert
|
||||
//speichert die plazierten gridBlöcke in einer Liste
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
|
||||
|
||||
Item ItemInHand = player.getMainHandStack().getItem();
|
||||
Block BlockInHand = getBlockFromItem(ItemInHand);
|
||||
//ItemStack ItemStackInHand = player.getMainHandStack();
|
||||
BlockPos gridBlockPos = hitResult.getBlockPos();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
player.sendMessage(Text.of(world.getBlockState(hitResult.getBlockPos()).getBlock().toString()));
|
||||
|
||||
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}")) {
|
||||
|
||||
|
||||
|
||||
if (player.isSpectator() == false) {
|
||||
|
||||
|
@ -45,33 +51,58 @@ public class useBlockCallback implements UseBlockCallback {
|
|||
return ActionResult.PASS;
|
||||
} else {
|
||||
player.sendMessage(Text.of("es hat funktioniert"));
|
||||
|
||||
|
||||
|
||||
/* BlockState StateInHand = BlockInHand.getDefaultState();
|
||||
BlockPos gridBlockPos = hitResult.getBlockPos();
|
||||
world.setBlockState(gridBlockPos, StateInHand);*/
|
||||
//hitResult.getBlockPos().getClass();
|
||||
|
||||
|
||||
player.getMainHandStack().decrement(1);
|
||||
|
||||
List <Position> gridBlockList = new LinkedList<Position>();
|
||||
gridBlockList.add(hitResult.getPos());
|
||||
|
||||
BlockState StateInHand = BlockInHand.getDefaultState(); //tauscht den blockstate des benutzen gridBlocks mit dem blockstate des blocks in der Hand
|
||||
world.setBlockState(gridBlockPos, StateInHand);
|
||||
|
||||
|
||||
|
||||
BlockState gridBlockState = world.getBlockState(hitResult.getBlockPos());
|
||||
Block gridBlock = gridBlockState.getBlock();
|
||||
|
||||
//BlockRenderView gridBlockRenderView;
|
||||
|
||||
//BlockState height = world.getBlockState(gridBlockPos).getAppearance(gridBlockRenderView, gridBlockPos, null, gridBlockState, gridBlockPos)
|
||||
|
||||
BlockRenderType gridBlockRender = gridBlock.getRenderType(gridBlockState);
|
||||
BlockRenderType inHandRenderType = BlockInHand.getRenderType(StateInHand);
|
||||
|
||||
player.sendMessage(Text.of(gridBlockRender.toString()));
|
||||
player.sendMessage(Text.of(inHandRenderType.toString())); //return: MODEL
|
||||
|
||||
|
||||
|
||||
//BlockRenderManager blockRenderManager = client.getRenderManager();
|
||||
|
||||
//BakedModel gridBlockModel = blockRenderManager.getModel(gridBlockState);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//gridBlockRender = FORCE_STATE;
|
||||
|
||||
|
||||
//hitResult.getBlockPos().getClass();
|
||||
|
||||
|
||||
//minecraft:blockid
|
||||
|
||||
/* if (player.getMainHandStack().equals("") ){ //TODO: wenn Werkzeuge in MainHand NICHT den MainHandStack reduzieren
|
||||
player.getMainHandStack().decrement(1); //TODO: sobald Hammer existiert darf gridBlock nur noch von diesem abgebaut werden können
|
||||
//TODO: sobald Hammer existiert darf gridBlock nur noch von diesem abgebaut werden können
|
||||
} else {
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
// BlockState gridBlockState = world.getBlockState(hitResult.getBlockPos());
|
||||
// Block gridBlock = gridBlockState.getBlock();
|
||||
|
||||
//BlockRenderType gridBlockRender = gridBlock.getRenderType(gridBlockState);
|
||||
// BlockRenderType inHandRenderType = BlockInHand.getRenderType(StateInHand);
|
||||
|
||||
|
||||
|
||||
// gridBlock.getAppearance(gridBlockState, BlockRenderView renderView,
|
||||
// gridBlockPos, Direction side, BlockState sourceState, BlockPos sourcePos);
|
||||
|
||||
|
@ -96,6 +127,10 @@ public class useBlockCallback implements UseBlockCallback {
|
|||
}
|
||||
return ActionResult.SUCCESS;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}// mit SUCCESS; FAIL wird kein Block mehr gesetzt
|
||||
// mit PASS; CONSUME; CONSUME_PARTIAL werden immer Blöcke gesetzt
|
||||
|
||||
|
|
Loading…
Reference in New Issue