Error Syntax error on token ";", , expected - Minecraft - java

I am creating a Minecraft mod, and I am getting the error Syntax error on token ";", , expected on this line
public static Block BasaltSmooth;
Here is the code :
package BitBox.Mods.BetterEgg;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
#Mod(modid = "BitBox's Mod", name = "BitBoxMod", version = "V0.1")
#NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class mainClass {
// Initialization
//tabs
public static Item BitBoxTabIcon;
//items
//blocks
public static Block BasaltSmooth;
BasaltSmooth = new BitBoxBlock(500, Material.rock)
.setHardness(0.5F)
.setUnlocalizedName("Basalt Stone")
.setCreativeTab(CreativeTabs.tabBlock);
public static CreativeTabs bitBoxTab;
#EventHandler
public void load(FMLInitializationEvent event) {
LanguageRegistry.addName(BasaltSmooth, "Basalt Stone");
MinecraftForge.setBlockHarvestLevel(BasaltSmooth, "pickaxe", 0);
GameRegistry.registerBlock(BasaltSmooth, "Basalt Stone");
}
public mainClass() {
}
}

You cant do like this
public static Block BasaltSmooth;
BasaltSmooth = new BitBoxBlock(500, Material.rock).setHardness(0.5F).setUnlocalizedName("Basalt
Stone").setCreativeTab(CreativeTabs.tabBlock);
Do like this
public static Block BasaltSmooth = new BitBoxBlock(500, Material.rock).setHardness(0.5F).setUnlocalizedName("Basalt
Stone").setCreativeTab(CreativeTabs.tabBlock);

Prabhakaran's answer should help you with instantiating the Block correctly, Minecraft can be picky at times. Howerever, another issue is that you should register it in the FML PreInit phase:
class{
create block with properties here.
#EventHandler
public void preInit(FMLPreInitializationEvent event) {
Register block with game here
}
}

Related

Block texture load only when placed, but not in inventory

I've read some other 'similar' questions but their problems is exactly the opposite. I've also read the docs but they won't provide anything useful to this problem.
When I /give myself the block, it shows a missing texture in my inventory as a item. But when I place it, its texture is shown in the world as a block.
Screenshot:
Main mod class:
package com.byethost8.code2828.mcmods.chemc;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.OreBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
#Mod(CheMC_.modid)
public class CheMC_ {
public static final String modid = "chemc";
public static OreBlock ore_lithium = (OreBlock) new OreBlock(
AbstractBlock.Properties
.create(Material.ROCK, MaterialColor.PINK_TERRACOTTA)
.harvestLevel(1)
.hardnessAndResistance(1, 1)
.setLightLevel(
light -> {
return 1;
}
)
)
.setRegistryName("chemc", "lithium_ore");
public static BlockItem i_ore_lithium = (BlockItem) new BlockItem(
ore_lithium,
new Properties().group(ItemGroup.BUILDING_BLOCKS)
)
.setRegistryName(ore_lithium.getRegistryName());
public static Block block_lithium = new Block(
AbstractBlock.Properties
.create(Material.IRON, MaterialColor.PINK_TERRACOTTA)
.harvestLevel(1)
.hardnessAndResistance(1.2F, 1)
.setLightLevel(
light -> {
return 1;
}
)
)
.setRegistryName("chemc", "lithium_block");
public static BlockItem i_block_lithium = (BlockItem) new BlockItem(
block_lithium,
new Properties().group(ItemGroup.BUILDING_BLOCKS)
)
.setRegistryName(block_lithium.getRegistryName());
public CheMC_() {
FMLJavaModLoadingContext
.get()
.getModEventBus()
.addListener(this::setup);
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event) {}
// You can use EventBusSubscriber to automatically subscribe events on the
// contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
#Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
#SubscribeEvent
public static void onBlocksRegistry(
final RegistryEvent.Register<Block> blockRegistryEvent
) {
// register a new block here
blockRegistryEvent
.getRegistry()
.registerAll(ore_lithium, block_lithium);
}
}
}
Some codes are removed to make the main problem clear.
Following texts only will say about Lithium Block, but same things apply for Lithium Ore.
Model File:
{
"parent": "block/cube_all",
"textures": {
"all": "chemc:block/lithium_block"
}
}
Folder structure of src/main/resources:
Blockstate:
{
"variants": {
"": [
{ "model": "chemc:block/lithium_block" }
]
}
}
I can't believe that I was stupid enough to register a Item and do nothing to assets/chemc/resources/models/item/ folder. See this for more. I have the exactly same problem as that OP.

Vaadin form raises inexistent syntax errors

I am trying to create a sample CRM for a student project. Currently, I am utilising springboot and vaadin in the STS4. I am using components from their cookbook and the vaading crm tutorial and the their bookstore sample projects from github as templates (i am kind of mixing up the elements of the two, perhaps my lack of understanding is what causes me this trouble). In the form for submission, the following errors are raised in lines 67 and 49: "Syntax error on token ";", { expected after this token" and "Syntax error, insert "}" to complete Block". I am adding my complete form for your inspection, hopefully, someone can explain to me, what is causing the error. Here is "my" code:
package com.vaadin.tutorial.crm.UI.views.list;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.checkbox.CheckboxGroup;
import com.vaadin.flow.component.checkbox.CheckboxGroupVariant;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.component.listbox.ListBox;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.KeyModifier;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.Result;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.data.binder.ValueContext;
import com.vaadin.flow.shared.Registration;
import com.vaadin.tutorial.crm.backend.entity.Disponibilite;
import com.vaadin.tutorial.crm.backend.entity.Livre;
import com.vaadin.tutorial.crm.backend.entity.Livre.Categorie;
import com.vaadin.tutorial.crm.backend.entity.Stock;
import com.vaadin.flow.data.converter.Converter;
import com.vaadin.flow.data.converter.StringToIntegerConverter;
import java.util.List;
import java.util.Set;
public class LivreForm extends FormLayout{
private Livre livre;
private final Select<Disponibilite> disponibilite;
private final TextField stockCount;
TextField titreLivre = new TextField("titreLivre");
TextField description = new TextField("description");
TextField auteur = new TextField("auteur");
TextField refeni = new TextField("refeni");
TextField isbn = new TextField("isbn");
stockCount = new TextField("In stock");
stockCount.addThemeVariants(TextFieldVariant.LUMO_ALIGN_RIGHT);
stockCount.setValueChangeMode(ValueChangeMode.EAGER);
disponibilite = new Select<>();
disponibilite.setLabel("Disponibilite");
disponibilite.setWidth("100%");
disponibilite.setItems(Disponibilite.values());
content.add(disponibilite);
ComboBox<Livre.Categorie> categorie = new ComboBox<>("Categorie");
ListBox<Stock> stock = new ListBox<Stock>();
ComboBox<Livre.Campus> campus = new ComboBox<>("Campus");
Button save = new Button("Save");
Button delete = new Button("Delete");
Button close = new Button("Cancel");
Binder<Livre> binder = new BeanValidationBinder<>(Livre.class);
public LivreForm(List<Stock> stocks) {
addClassName("livre-form");
binder.bindInstanceFields(this);
stock.setItems(stocks);
disponibilite.setItems(Disponibilite.values());
categorie.setItems(Livre.Categorie.values());
campus.setItems(Livre.Campus.values());;
add(titreLivre,
description,
auteur,
refeni,
isbn,
disponibilite,
categorie,
campus,
stock,
createButtonsLayout());
}
public void setLivre(Livre livre) {
this.livre = livre;
binder.readBean(livre);
}
private Component createButtonsLayout() {
save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
delete.addThemeVariants(ButtonVariant.LUMO_ERROR);
close.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
save.addClickShortcut(Key.ENTER);
close.addClickShortcut(Key.ESCAPE);
save.addClickListener(event -> validateAndSave());
delete.addClickListener(event -> fireEvent(new DeleteEvent(this, livre)));
close.addClickListener(event -> fireEvent(new CloseEvent(this)));
binder.addStatusChangeListener(e -> save.setEnabled(binder.isValid()));
return new HorizontalLayout(save, delete, close);
}
private void validateAndSave() {
try {
binder.writeBean(livre);
fireEvent(new SaveEvent(this, livre));
} catch (ValidationException e) {
e.printStackTrace();
}
}
public static abstract class LivreFormEvent extends ComponentEvent<LivreForm> {
/**
*
*/
private static final long serialVersionUID = -7236023661050023675L;
private Livre livre;
protected LivreFormEvent(LivreForm source,Livre livre) {
super(source, false);
this.livre = livre;
}
public Livre getLivre() {
return livre;
}
}
public static class SaveEvent extends LivreFormEvent {
SaveEvent(LivreForm source, Livre livre) {
super(source, livre);
}
}
public static class DeleteEvent extends LivreFormEvent {
DeleteEvent(LivreForm source, Livre livre) {
super(source, livre);
}
}
public static class CloseEvent extends LivreFormEvent {
CloseEvent(LivreForm source) {
super(source, null);
}
}
public <T extends ComponentEvent<?>> Registration addListener(Class<T> eventType,
ComponentEventListener<T> listener) {
return getEventBus().addListener(eventType, listener);
}
#SuppressWarnings("serial")
private static class StockCountConverter extends StringToIntegerConverter {
public StockCountConverter() {
super(0, "Could not convert value to " + Integer.class.getName()
+ ".");
}
}
}
And this is a screenshot of the errors:
the lines that cause unexplainable errors
= new BeanValidationBinder<>(Livre.class)
Use new Binder<> instead of beanvalidation binder

Adding Potion Effect when Item is in hand Minecraft Forge 1.16.5

So Basically I have been searching the internet for a way to add potion effects while an item is being held. I have found many results but none really seem to be working. My main issue is that when I get to the adding potion effect it throws errors because I am trying to use a non-static to access an abstract. I tried the #Overide several times but it never seems to work. I still need to register in forge as that is how it updates but adding PlayerEntity does not work when I use #SubscribeEvent
package blitz.weapon.weaponmod;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.stream.Collectors;
// The value here should match an entry in the META-INF/mods.toml file
#Mod("weaponmod")
public class Weaponmod {
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "weaponmod");
public static final RegistryObject<Item> RAINBOW_SWORD = ITEMS.register("rainbow_sword", () ->
new Item(new Item.Properties()
.group(ItemGroup.COMBAT)
.maxStackSize(1)
.maxDamage(13)
));
public Weaponmod() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
}
#SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.side.isServer() && event.phase == TickEvent.Phase.START) {
ItemStack stack = event.player.getHeldItemMainhand();
if (stack != null && stack.getItem() !=null) {
if (stack.getItem().equals("1 rainbow_sword")) {
return;
}
}
}
}
private void setup(final FMLCommonSetupEvent event) {
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}
private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
}
private void enqueueIMC(final InterModEnqueueEvent event) {
// some example code to dispatch IMC to another mod
InterModComms.sendTo("weaponmod", "helloworld", () -> {
LOGGER.info("Hello world from the MDK");
return "Hello world";
});
}
private void processIMC(final InterModProcessEvent event) {
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m -> m.getMessageSupplier().get()).
collect(Collectors.toList()));
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
#SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
// do something when the server starts
LOGGER.info("HELLO from server starting");
}
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
#Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
#SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// register a new block here
LOGGER.info("HELLO from Register Block");
}
}
}
That is my code for basically my whole mod, can anyone give me any pointers? (Sorry for any mistakes this is my first post)

Error: Could not pass event PlayerJoinEvent to Plugin (BUKKIT)

I'm doing a test plugin, and when I log in, it doesn't tell me the login message, but it gives me an error. Here is the log: https://pastebin.com/SyBN5G2k
I looked up in internet but I can't found nothing that helps me.
Can someone help me i need it to make my server!
This the code of the PlayerJoinEvent event :
package com.Test.events;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import com.Test.main.MClass;
public class Enter implements Listener{
private MClass plugin;
public Enter(MClass plugin) {
this.plugin = plugin;
}
#EventHandler
public void onEnter(PlayerJoinEvent event) {
Player player = event.getPlayer();
Location spawn = new Location(player.getWorld(), -8, 64, -467.0, -90, 0);
player.teleport(spawn);
FileConfiguration config = plugin.getConfig();
String path = "config.welcome-message";
if(config.getString(path).equals("true")) {
String text = "Config.welcome-message-text";
player.sendMessage(config.getString(text));
}
}
}
And this my main class (called MClass)
package com.Test.main;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.Test.commands.CommandPotatoes;
import com.Test.commands.PrincipalCommand;
import com.Test.events.Enter;
public class MClass extends JavaPlugin{
public String configPath;
PluginDescriptionFile pdffile = getDescription();
//Declaration on variables thas include info of the version and the name
public String name = ChatColor.GOLD+""+ChatColor.BOLD+"["+pdffile.getName()+"] "+ChatColor.RESET;
public String version = pdffile.getVersion();
//Instruction on enable plugin
public void onEnable() {
//Mensaje de la consola que indica que el plugin ha sido activado
Bukkit.getConsoleSender().sendMessage(name+ChatColor.BLUE+"Sucesfully loaded (ver "+version+")");
registerCommands();
registerEvents();
registerConfig();
}
public void registerCommands() {
this.getCommand("potatoes").setExecutor(new CommandPotatoes(this));
this.getCommand("test").setExecutor(new PrincipalCommand(this));
}
public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new Enter(this), this);
}
public void registerConfig() {
File config = new File(this.getDataFolder(),"config.yml");
configPath = config.getPath();
if(!config.exists()) {
this.getConfig().options().copyDefaults(true);
saveConfig();
}
}
}
Plz help i need it to make my server :(
This is what you are looking for:
Caused by: java.lang.NullPointerException
at com.Test.events.Enter.onEnter(Enter.java:27) ~[?:?]
Line #27 would be if(config.getString(path).equals("true"))
Check whether there is indeed a string at that path, meaning
config:
welcome-message: true
as a side note, you should use boolean types for truth values, not strings.

requireThat() and requireSingleCommand() are undefined

I am new to Corda and started with the provided tutorials.
In two different tutorials I ran into the same problem. The functions requireThat() and requireSingleCommand() are undefined.
Below you see my code from the "HelloWorld! Pt. 2" tutorial.
The requireThat() function produces the following error:
The method requireThat((<no type> require) -> {}) is undefined for the type SignTxFlow Java(67108964)
Although, the requireThat() function is part of the net.corda.core.contracts package which is included in the code.
Thank you for your help!
package com.template.flows;
import com.template.states.IOUState;
import co.paralleluniverse.fibers.Suspendable;
import net.corda.core.contracts.ContractState;
import net.corda.core.crypto.SecureHash;
import net.corda.core.flows.FlowException;
import net.corda.core.flows.FlowLogic;
import net.corda.core.flows.FlowSession;
import net.corda.core.flows.InitiatedBy;
import net.corda.core.flows.ReceiveFinalityFlow;
import net.corda.core.flows.SignTransactionFlow;
import net.corda.core.transactions.SignedTransaction;
import net.corda.core.contracts.*;
import net.corda.core.flows.*;
import net.corda.core.contracts.Command;
import net.corda.core.transactions.*;
import net.corda.core.utilities.ProgressTracker;
// ******************
// * Responder flow *
// ******************
#InitiatedBy(IOUFlow.class)
public class IOUFlowResponder extends FlowLogic<Void> {
private FlowSession otherPartySession;
public IOUFlowResponder(FlowSession otherPartySession) {
this.otherPartySession = otherPartySession;
}
#Suspendable
#Override
public Void call() throws FlowException {
class SignTxFlow extends SignTransactionFlow {
private SignTxFlow(FlowSession otherPartySession) {
super(otherPartySession);
}
#Override
protected void checkTransaction(SignedTransaction stx) {
requireThat(require -> {
ContractState output = stx.getTx().getOutputs().get(0).getData();
require.using("this must be an IOU transaction. ", output instanceof IOUState);
IOUState iou = (IOUState) output;
require.using("The IOU's value can't be too high.", iou.getValue() < 100);
return null;
});
}
}
SecureHash expectedTxId = subFlow(new SignTxFlow(otherPartySession)).getId();
subFlow(new ReceiveFinalityFlow(otherPartySession, expectedTxId));
return null;
}
}
The problem is solved, if the package
import static net.corda.core.contracts.ContractsDSL.requireThat;
is implemented at the top.

Categories

Resources